Nns_ninteyFIve
Nns_ninteyFIve

Reputation: 37

Streamprovider i am getting this issue "The following ProviderNotFoundException was thrown building ConsumerStreamData

error popup on terminal window

main.dart file contain all the providers

  return MultiProvider(
          providers: [
            ChangeNotifierProvider(create: (context)=>AppData()),
            ChangeNotifierProvider(create: (context)=> UtilData()),
            ChangeNotifierProvider(create: (context)=> ButtonData()),
            StreamProvider(create: (context)=> streamProvider.getScanningData(),
                initialData: false),
          ],

so in another statefulwidget class in appbar im trying to get that stream value using consumer widget and i am getting this ,

appBar: AppBar(
leading: Padding(
padding: EdgeInsets.only(
left: SizeConfig.blockSizeHorizontal * 1.5,
),
child: InkWell(
onTap: (){
print('presed');
_scaffoldKey1.currentState?.openDrawer();
},
child: Container(
decoration: BoxDecoration(
color: Colors.grey[100], // border color
shape: BoxShape.circle,
),
actions: [
   Consumer<StreamData>(
   builder: (_,value,__){
    if(value == true )
    return Text('true');
    else
   return Text('false');
     },
    ),
  ],
 ),

this is my stream class that gets bluetooth data

class StreamData{

   Stream<bool> getScanningData(){
    return FlutterBluePlus.instance.isScanning;
  }

Upvotes: 0

Views: 106

Answers (1)

Rishan Shrestha
Rishan Shrestha

Reputation: 76

In consumer widget you code should be

 Consumer<bool>(
   builder: (_,value,__){
    if(value)
    return Text('true');
    else
   return Text('false');
     },
    ),

Upvotes: 1

Related Questions