Flutter : Error: Could not find the correct Provider<NotificationBloc> above this NotificationPage Widget

2,384 views
Skip to first unread message

Sourav Roy

unread,
Jul 21, 2020, 12:52:11 PM7/21/20
to Flutter Development (flutter-dev)

 am trying to call a Page from a home page navigation drawer, but getting the above error regarding providers where I am passing a bloc to update the page in a stream builder.

Below is the code for calling the page:

Navigator.push(context, PageRoutes(page:
    NotificationPage()));

And in the build widget I have Scaffold and the body has the below code:

Widget build(BuildContext context) {
    final 
    notificationBloc=Provider.of<NotificationBloc> 
    (context);
        return 
        Scaffold(
        appBar: AppBar(title:Text('Tiles')),
        body: Provider<NotificationBloc>(
        create: (_)=>NotificationBloc(),    
        builder:(context,_){
         
              return Column(
                children: [
                  StreamBuilder<List<NotificationModel>>(
                        stream: notificationBloc.notifications,
                        builder: (context, snapshot) {
                          if(snapshot.hasData){
                            final notifications=snapshot.data;
                            _fadeInController.forward();
                            if(notifications.isEmpty){
                              return Container();
                            }
                            return Expanded(
                  child: AnimatedBuilder(
                    animation: _fadeInController,
                    builder: (context, child) {
                      return Opacity(
                        opacity: _fadeInController.value,
                        child: ListView.builder(
                          padding: const EdgeInsets.all(12),
                          itemCount: notifications.length,
                          itemBuilder: (context, index) {
                            final notification = notifications[index];
                            return NotificationTile(
                              notification: notification,
                            );
                          },
                        ),
                      );
                    },
                  ),
            );
            }
            return Expanded(child: SizedBox());
                        }
                  ),
               
      //     CustomWideFlatButton(
        //onPressed: navigateToNotificationCreation,
        //backgroundColor: Colors.blue.shade300,
        //foregroundColor: Colors.blue.shade900,
        //isRoundedAtBottom: false,
          // )
         ],
              );
       }

But every time I click on the drawer icon to invoke the page, get the error in subject. Can you please help, I have tried multiple changes and tried to research it online but could not get any solution

Suzuki Tomohiro

unread,
Jul 21, 2020, 1:06:10 PM7/21/20
to Sourav Roy, Flutter Development (flutter-dev)
Use Flutter Inspector to see the widget tree. The error says  there’s no Provider in the parent widgets of the widget requests NotificationBloc.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/78c24afb-c802-4b0f-a475-37e8faf359c4o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages