How to use GraphQLProvider inside MultiProvider? - flutter

MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => AuthProvider(authService: AuthService()),
),
GraphQLProvider(...),
],
)
The element type GraphQLProvider can't be assigned to the list type SingleChildWidget.

Related

Provider trying to update my count when ever will I receive Notification?

I am unable to update my Ui
//// HERE I AM GETTING THE UPDATE DATA IN CONSOLE BUT UNABLT TO UPDATE INSIDE MY UI
My NotificationCountClass
class NotificationCount extends ChangeNotifier{
var count;
NotificationCount({
this.count =0,
});
addNotificationCount(){
count++;
notifyListeners();
print("Notification Count $count");
}
}
main : here i wrap the widget inside multiprovider so that i can use it any-where in my app
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AppService()),
ChangeNotifierProvider(create: (context) => NotificationCount()),
],
child: Consumer<AppService>(
builder: (context, appService, child) {
return GetMaterialApp(
title: AppStrings.APP_TITLE,
theme: AppTheme.lightTheme,
darkTheme: AppTheme.dartTheme,
navigatorKey: GlobalVariable.navigatorKey,
supportedLocales: [
Locale('en'),
],
localizationsDelegates: [
CountryLocalizations.delegate,
],
themeMode: appService.isDarkMode ? ThemeMode.dark : ThemeMode.light,
initialRoute: AppRouter.SPLASH_SCREEN,
onGenerateRoute: AppRouter.router.generator,
// routes: {
// "/":(context) =>Home(),
// "/AppChat" : (context) => AppChat(),
// },
debugShowCheckedModeBanner: false,
// home: AppChat(),
);
},
),
);
// Using State with Consumer widget so that only required wiget rebuild
Consumer<NotificationCount>(
builder: (context, value, child) {
var count = value.count;
print("Count of Not : $count");
return Text(
"$count",
style: TextStyle(
color: Colors.white,
),
);
},
),
getting NotificationCount class with provider but still unable to update UI
final notificationCount = Provider.of<NotificationCount>(context , listen: false);
I could reproduce your issue on my side, and could fix it just by using the builder of MultiProvider instead of child.
Instead of
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AppService()),
ChangeNotifierProvider(create: (context) => NotificationCount()),
],
child: Consumer<AppService>(
write somthing like:
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AppService()),
ChangeNotifierProvider(create: (context) => NotificationCount()),
],
builder: (context, _) => Consumer<AppService>(
...

SreamProvider containing specific documents

I have a streamProvider that contains all of the documents from a collection.
I want a StreamProvider that contains only certain documents. Can I use .where('agency', isEqualTo: 'some name'? Can this be done and if so how do I do it? Below is my current code:
'''
// From the main.dart
return MultiProvider(
providers: [
StreamProvider(create: (context) => firestoreService.getTrxns()),
],
child: MaterialApp(
initialRoute: WelcomeScreen.id,
routes: {
WelcomeScreen.id: (context) => WelcomeScreen(),
Home_Screen.id: (context) => Home_Screen(),
},
/// This is from a Services.dart file
Stream<List<Trxns>> getTrxns() {
return _db.collection('trxns').snapshots().map((snapshot) => snapshot.docs
.map((document) => Trxns.fromFirestore(document.data()))
.toList());
}
'''
That's exactly how you would do it:
_db.collection('trxns').where('agency', isEqualTo:
'some name').snapshots().map()

Flutter BLOC and Provider how to register them together

I'm writing an app using BLOC architecture and registered bloc providers like this in the main.dart:
runApp(MultiBlocProvider(providers: [
BlocProvider<OrderBloc>(
create: (context) {
return OrderBloc()..add(OrderInitialEvent());
},
),
BlocProvider<AuthenticationBloc>(
create: (context) {
return AuthenticationBloc(userService: userService)..add(AppStarted());
},
),
...
], child: MyApp()));
Now I need to use Provider approach along with BLOC but not sure how to register it? Is it possible? Thanks
You can just nest them:
runApp(MultiBlocProvider(providers: [
BlocProvider<OrderBloc>(
create: (context) {
return OrderBloc()..add(OrderInitialEvent());
},
),
BlocProvider<AuthenticationBloc>(
create: (context) {
return AuthenticationBloc(userService: userService)..add(AppStarted());
},
),
...
],
child:
MultiProvider(
providers: [
Provider<Something>(create: (_) => Something()),
Provider<SomethingElse>(create: (_) => SomethingElse()),
Provider<AnotherThing>(create: (_) => AnotherThing()),
],
child: MyApp(),
)));

How to use Multiple Providers in flutter

I'm trying to use Multiple providers in my application, but i'm facing some compile time error at builder by using below code
Code
ChangeNotifierProvider(builder: (_) => FirstProvider()),
ChangeNotifierProvider(builder: (_) => SecondProvider()),
you can use MultiProvider to do so. as following.
MultiProvider(
providers: [
ChangeNotifierProvider(builder: (_) => FirstProvider()),
ChangeNotifierProvider(builder: (_) => SecondProvider()),
],
child: someWidget,
)
Hey builder was deprecated you can refer this link for more info Builder Deprecation
We can use Multiple providers like this
MultiProvider(
providers: [
ChangeNotifierProvider<ProductDataProvider>(
create: (_) => ProductDataProvider()),
ChangeNotifierProvider<AuthenticationProvider>(
create: (_) => AuthenticationProvider()),
],
child: Container())
You can use it like this:
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => CartModel()),
Provider(create: (context) => SomeOtherClass()),
],
child: MyApp(),
),

Flutter ChangeNotifierProvider the parameter 'update' is required

with the latest updates I got this:
warning: The parameter 'update' is required. . (missing_required_param
at [pos_mobile] lib\main.dart)
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
),
ChangeNotifierProxyProvider<Auth, Operatori>( // here I got the warning
builder: (ctx, auth, prevData) => Operatori(auth.token, auth.userId,
prevData == null ? [] : prevData.operatori),
),
thanks
Check the ChangeNotifierProxyProvider doc
It should be :
ChangeNotifierProxyProvider<Foo, MyChangeNotifier>(
create: (_) => MyChangeNotifier(),
update: (_, foo, myNotifier) => myNotifier
..foo = foo,
child: ...
);