flutter hook useContext example

Issue

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),
      ),
    );
  }

Answered By – Mavya Soni

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.