0

Is it recommended to use useMemoized() in Flutter hooks for images and/or media query size when using animations in the widget?

    final shortSide = useMemoized(() => MediaQuery.of(context).size.shortestSide);
    Image image = useMemoized(() => Image.file/asset());
    final animation = useAnimationController(duration: const duration);
  • 1
    if it works for you, go right ahead. It's really no different from setting up a property of your State and adding the appropriate initState method, except that you can trigger it from within the first build after you may have examined some other shared state. Just remember to keep your hooks unconditional... I like to put them all right at the beginning of build. – Randal Schwartz May 23 '23 at 18:11

0 Answers0