2021年1月19日星期二

Pass and update State Value from other function Flutter Hook Widget

I am new to Flutter hooks and I have requirements that I have to use HookWidget instead of StatefulWidget. As I know, useState can only be declared within the build function.

Widget build(BuildContext context) {      final selectedBook = useState("");      return Container(         child: _buildBookListContainer(context)      )    }    Widget _buildBookListContainer(BuildContext context) {    //I will want to update the state value or read the state value in the child function    //how do I do that?    //Example: selectedBook.value = "xxx";  }  

I tried passing down the state value as function arguments but it will not work. May I know that is it all HookWidget class will just write all components inside the build function without refractoring?

https://stackoverflow.com/questions/65802951/pass-and-update-state-value-from-other-function-flutter-hook-widget January 20, 2021 at 12:07PM

没有评论:

发表评论