Following this question, I understand why StatefulWidgets do make sense in the context of a Redux-based flutter app. And that's what I'm trying to accomplish as well-
a Page that is "fed" information from the app-wide state (logged in user details, api data, etc) and can also dispatch actions from it's connected ViewModel, but one that ALSO contains stateful widgets with a smaller scope, short-lived state. things like Animation, validating user input on the fly before submitting, and changing the UI based on user actions.
So I'm interested in the how and hope someone here can help me. Currently all of my "pages" are stateless widgets connected to the app-state via the store, in the following manner:
class LoginPage extends StatelessWidget {
final String TAG = "LoginPage";
bool isGreen = false;
LoginPage({Key key}) : super(key: key);
void changeColor() {
isGreen = !!isGreen;
}
@override
Widget build(BuildContext context) {
/// [StoreConnector] is used to convert store data (using the fromStore)
/// into a ViewModel suitable for the page.
return StoreConnector<AppState, LoginPageViewModel>(
builder: (context, viewModel) {
return Scaffold(
body: Column(
children: <Widget>[
Container(...),
Text(
text: viewModel.some_value_from_the_store,
color: isGreen ? Colors.green : Colors.red,
),
ElevatedButton(
onPressed: () => changeColor(),
child: Text('Press to change color'),
)
],
));
},
converter: LoginPageViewModel.fromStore);
}
}
Here I'm just trying to simply change the text color inside the "LoginPage" widget, based on user clicks, while still remain connected to the store so that the UI keeps updating with new app-state information as it arrives.
Is there any reference for something like this our there? can anyone provide an example, or just the basic guidelines of how to achieve this? seems simple, but I'm struggling with it.