1

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;
  }

James Z
  • 12,209
  • 10
  • 24
  • 44
Nns_ninteyFIve
  • 439
  • 4
  • 12

1 Answers1

2

In consumer widget you code should be

 Consumer<bool>(
   builder: (_,value,__){
    if(value)
    return Text('true');
    else
   return Text('false');
     },
    ),
  • how consumer identify the data without mentioning the StreamData class? – Nns_ninteyFIve Apr 18 '23 at 18:41
  • 1
    StreamProvider(create: (context)=> streamProvider.getScanningData(), initialData: false), streamProvider.getScanningData() returns bool, therefore You are creating a streamprovider of boolean value instead of a StreamData, so u need to consume a boolean value – Rishan Shrestha Apr 19 '23 at 03:39
  • ok fine , if i am using one more streamprovider in multiproviders with bool type is this work? – Nns_ninteyFIve Apr 19 '23 at 06:24
  • If u want to use one or more boolean streamprovider, then it wont allow you, instead either create a changenotifier provider or instead of providing a boolean, provide a class – Rishan Shrestha Apr 20 '23 at 09:34