Home:ALL Converter>bloc sink was called null

bloc sink was called null

Ask Time:2019-08-28T04:36:22         Author:BIS Tech

Json Formatter

I used imagePicker. I need to assign a profile photo after add. Last time I user setState() but not working.

my bloc class look like this,

class ImageBloc {
  final _loadingController = StreamController<String>();
  Stream<String> get loadingStream => _loadingController.stream;

  void setIsLoading(String image) => _loadingController.add(image);

  dispose() {
    _loadingController.close();
  }
}

Player class This class is StatefullWidget

class _PlayersState extends State<Players> {
   ImageBloc bloc;
...
drawer: drawer(context, onProfilePictureChanged,bloc),
}

drawer this is a common drawer. I used this method in other class. other class, I passed null to bloc parameter

Widget drawer(BuildContext context, onProfilePictureChanged,ImageBloc bloc) {
  return Drawer(
    child: Container(child:
//I checked bloc null or not because others class I passed null value to bloc
                    bloc == null ? Text("null value",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 13.0,
                        fontWeight: FontWeight.w500,
                      )):
//Player class only I passed bloc
                    StreamBuilder<String>(
                      stream: bloc.loadingStream,
                        initialData: "bloc value",
                        builder: (context,snapshot){
                          return Text(snapshot.data,
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 13.0,
                                fontWeight: FontWeight.w500,
                              ));
                    }),))

I passed bloc for set value to sink..

 await showDialog(
        context: context,
        builder: (BuildContext context) {
          return ProfilePop(bloc:bloc);
        });

ProfilePop class

class ProfilePop extends StatefulWidget {
  const ProfilePop({Key key, @required this.bloc}) : super(key: key);
  final ImageBloc bloc;
}

class ProfilePopState extends State<ProfilePop>{

  upload(File imageFile) async {
   ...
      setState(() {
        global.profileImage = uploadedImage["Photo"];
        widget.bloc.setIsLoading(uploadedImage["Photo"]);
      });
...
  @override
  Widget build(BuildContext context) {
    void onCancelPressed() {
      Navigator.pop(context);
    }

    return new AlertDialog(
      title:global.image == null
                    ? profile
                    : new Container(
                       ...
                      ),
        ),
      ),);}
});}}

Author:BIS Tech,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57681922/bloc-sink-was-called-null
yy