flutterflutter-hooks

flutter hook useContext example


Is there any example of useContext() function example? I want to use

AppLocalizations.of(context).someText 

in many of hook widgets and I am not sure if it is just enough to wrap it in useEffect function on initialize.


Solution

  • We can use like this.

    Widget _getAccountRegister() {
        final context = useContext();
        return Container(
          margin: const EdgeInsets.all(10),
          child: FlatButton(
            padding: const EdgeInsets.all(10),
            onPressed: () {
              NavigationUtils.push(context, routeRegister);
            },
            child: Text(Localization.of(context).signIn),
          ),
        );
      }