[Official ROM]You don't need to flash to install magisk but if you are getting boot loop then download the fastboot ROM, flash the device. Some ROM contains flash_all.sh file. Go to fasboot mode.
adb reboot bootloader
then ./flash_all.sh
Then setup the phone install the magisk.apk (Magisk Manager)and patch the boot.img from the rom. Enable USB debugging and again go to the fast boot mode.
adb reboot bootloader
fastboot devices
fastboot flash boot boot.img
fastboot reboot