push data from another widget flutter with provider code example
Example 1: pass string to a provider flutter
class SecondPage extends StatelessWidget { final Data data; SecondPage({this.data}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(‘Constructor — second page’), ), body: Container( padding: EdgeInsets.all(12.0), alignment: Alignment.center, child: Column( children: [ Container( height: 54.0, padding: EdgeInsets.all(12.0), child: Text(‘Data passed to this page:’, style: TextStyle(fontWeight: FontWeight.w700))), Text(‘Text: ${data.text}’), Text(‘Counter: ${data.counter}’), Text(‘Date: ${data.dateTime}’), ], ), ), ); }}
Example 2: pass data from one provider model to anothe
GetIt locator = GetIt();locator.registerLazySingleton(() => Api());locator.registerLazySingleton(() => AuthenticationService());locator.registerLazySingleton(() => LoginModel());// Usagevar api = locator()