Created
July 23, 2020 21:10
-
-
Save DevKhalyd/db3695efb986e7a5644e4d565c29f9c9 to your computer and use it in GitHub Desktop.
ProxyProvider Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:vento_app/notifiers/data_stores_notifiers.dart'; | |
import 'package:vento_app/notifiers/search_item.dart'; | |
//ProxyProvider | |
class SearchStoreProxy { | |
//Notifier | |
DataStoreNotifier _dataStore; | |
//Notifier | |
SearchItemNotifier _searhItems; | |
//Constructor | |
SearchStoreProxy(this._dataStore, this._searhItems); | |
DataStoreNotifier get dataStore => _dataStore; | |
SearchItemNotifier get searhItems => _searhItems; | |
} | |
//Use in main | |
MultiProvider( | |
providers: [ | |
ChangeNotifierProvider<SearchItemNotifier>( | |
create: (_) => SearchItemNotifier(), | |
), | |
ChangeNotifierProvider<DataStoreNotifier>( | |
create: (_) => DataStoreNotifier(), | |
), | |
//2 means classes to use | |
ProxyProvider2<SearchItemNotifier, DataStoreNotifier, | |
SearchStoreProxy>( | |
update: (context, item, store, proxy) => SearchStoreProxy( | |
store, | |
item, | |
), | |
) | |
], | |
child: MaterialApp( | |
title: 'Vento App', | |
initialRoute: initialRoute(), | |
debugShowCheckedModeBanner: false, | |
routes: { | |
LoginScreen.route: (c) => LoginScreen(), | |
ListStores.route: (c) => ListStores() | |
}, | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment