天道酬勤,学无止境

flutter-provider

How to "do" something if ChangeNotifier notifies with Provider Package (similar to BlocListener)?

What I want I have a simple model. The model extends from ChangeNotifier. If the ChangeNotifier calls notifyListeners() I want to "do" something like showing a SnackBar or Dialog. I provide the model with the Provider package to my widget tree. What is it comparable to? I used the flutter_bloc package before. This package offers BlocListener. With BlocListener I can "do" something on state changes. Example code: BlocListener<BlocA, BlocAState>( listener: (context, state) { // do stuff here based on BlocA's state }, child: Container(), ) In the above example, the child will not rebuild but I

2022-05-01 06:17:17    分类:问答    flutter   dart   flutter-provider

Provider state management for PageController in Flutter

I made a website with PageController to control the scroll of some screens. And I made a menu section with screen names, and when any of them are pressed, the user will navigate to the respective screen. The app is working fine. But I refactored the menu button so I can control it's style, and to add animation in the future. But when I refactored the button, I can't pass the PageController index, or the nextPage function. That's why I thought of using the provider package. However, I didn't the package before, and my setup seems complex. For I should pass the PageController state to the button

2022-05-01 00:00:51    分类:问答    flutter   flutter-web   flutter-provider

ProviderNotFoundException (Error: Could not find the correct Provider<LayoutData> above this SchedulingPage Widget using layoutBuilder

I'm getting a providerNotFoundException, and I suspect that there is a context mismatch in the below code, but I'm having a hard time seeing it. As I understand, problems with BuilderContext arise when an .of method is performed within the same build method, but I don't see this happening in this case. Some of the Provider.of methods work fine as annotated in the below code, but as soon as SchedulingPage is called, the Provider.of methods no longer work. What is the problem here? Edit: I updated to use my full code below: Here's the full error: ProviderNotFoundException (Error: Could not find

2022-04-30 06:09:34    分类:问答    flutter   flutter-provider

Can I wrap the MaterialApp widget with the Provider?

I'm new to flutter and I'm trying to create an app with provider. I wrapped MaterialApp widget with the ChangeNotifierProvider and the app works and I can use the provider as it intended to do. I need to know is it okay to do so and will i face any problems? Widget build(BuildContext context) { return ChangeNotifierProvider<BaseModel>( builder: (context) => BaseModel(loading: false, title: "Title", isLoggedIn: false), child: MaterialApp( routes: <String, WidgetBuilder>{ "/home": (BuildContext context) => Home(), "/signIn": (BuildContext context) => SignIn() }, initialRoute: "/signIn", title:

2022-04-27 16:27:23    分类:问答    flutter   dart   flutter-provider

Error: Could not find the correct Provider above this widget

This screen is a Drawer screen which take the auth bloc in order to provide user the info and enable him of logout. I got this error although I am using the correct provider The following ProviderNotFoundError was thrown building Pets4allDrawer(dirty): I/flutter (32011): Error: Could not find the correct Provider<AuthService> above this Pets4allDrawer Widget I/flutter (32011): To fix, please: I/flutter (32011): * Ensure the Provider<AuthService> is an ancestor to this Pets4allDrawer Widget I/flutter (32011): * Provide types to Provider<AuthService> I/flutter (32011): * Provide types to

2022-04-27 05:03:38    分类:问答    flutter   flutter-provider

flutter provider what is the difference with 'Context context' and 'context '

``` import 'package:a_class_flutter/provider/ac_score/ac_score_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:provider/provider.dart'; class ACScoreView extends StatelessWidget { @override Widget build(BuildContext context) { return ChangeNotifierProvider( create: (context) => ACScoreProvider(), builder: (context, child) { return Stack( children: <Widget>[ _topMenu(context), ], ); }, ); } } // Important! Widget _topMenu(BuildContext context) { return GestureDetector( onTap: () { context.read<ACScoreProvider>(

2022-04-06 04:01:28    分类:问答    flutter   flutter-provider

Consumer not rebuilding UI using riverpod

I'm trying to make simple stateNotifier with riverpod. When I click the button, it'll toggle between values. I've checked the value and it changes when pressing the button. The problem is the UI is not rebuilding itself. I've checked the docs and am pretty sure I've done correctly. Homescreen class HomeScreen extends StatefulWidget { @override _HomeScreenState createState() => _HomeScreenState(); } class _HomeScreenState extends State<HomeScreen> { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return SafeArea( child: Consumer( builder:

2022-03-23 13:45:19    分类:问答    flutter   dart   flutter-provider   riverpod

Use Provider to update Scaffold from a second screen

I want to have a Settings screen where I can choose a color to be returned to the first screen. I can't get the first screen to update when the Setting screen is closed. I'm using the Provider as a change notifier. But I can't see how to trigger the update of the first screen. The third button creates an event which updates the screen, but can this be done automatically? What am I missing...? import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; void main() => runApp(MyApp()); Color bgColor = Colors.yellow[100]; class MyApp extends StatelessWidget { @override Widget

2022-03-23 10:02:44    分类:问答    android   flutter   flutter-provider