I have MobX @action which successfully return a value. Wondering how to retrieve the value in initial screen load without click or tap anything.
abstract class _ProfileMobx with Store {
@observable
User user;
@observable
String name = '';
@action
Future getClientName() async {
SharedPreferences pref = await SharedPreferences.getInstance();
User user = User.fromJson(json.decode(pref.getString('userPref')));
name = user.name; //successfully return an username from this action
}
}
I hope I can get the username value and inserted automatically to text widget.
final ProfileMobx profileMobx = ProfileMobx();
class ProfileView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Text(profileMobx.name)
],
),
);
}
}
Thanks !!!