firebase - Error: A non-null value must be returned since the return type 'Never' doesn't allow null - TagMerge
4Error: A non-null value must be returned since the return type 'Never' doesn't allow nullError: A non-null value must be returned since the return type 'Never' doesn't allow null

Error: A non-null value must be returned since the return type 'Never' doesn't allow null

Asked 11 months ago
0
4 answers

Try upgrading flutter version to 2.10.3. The Error will be gone.

Source: link

0

From these lines, it seems like you are defining a function at line 37 that supposed to return a Widget, but instead return null. Keep in mind that when placing a widget within a screen in Flutter, that widget must not be null. You can catch the null widget with a blank Container like:
...
child: someWidget ?? Container()
...
StreamBuilder<QuerySnapshot>(
                stream: _FireData.collection('Text').snapshots(),
                builder: (
                  BuildContext context,
                  AsyncSnapshot snapshot,
                ) {
                  if (snapshot.hasData) {
                    final Messages = snapshot.data.docs;
                    List<Text> MessagesWeigets = [];
                    for (var message in Messages) {
                      final TextMessage = message.data['Text'];
                      final TextUser = message.data['User'];
                      final MessageWeiget = Text('$TextMessage From $TextUser');
                      MessagesWeigets.add(MessageWeiget);
                    }
                    return Column(
                      children: MessagesWeigets,
                    );
                  }

Source: link

0

Here is the Code
class Match extends StatefulWidget {

  @override
  State<Match> createState() => _MatchState();
}

class _MatchState extends State<Match> {
  
    getCricketScoreApi() async {
    var url = Uri.parse(api_url);
    var response = await get(url);
    if(response.statusCode == 200){
      final score = jsonDecode(response.body);
      return  score['cricket_score'];
    } else {
      return print('Something went wrong');
    }
  }

  Stream streamScore() { 
    return Stream.periodic(Duration(seconds: 1), (Timer) => getCricketScoreApi()); // Calling method after every 1 second
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      body: StreamBuilder(
          stream: streamScore(),
          builder: (context, snapshot){
              var cricket_score_api = snapshot.data.toString();
              if(snapshot.hasData){
                return Center(
                  child: Text(cricket_score_api, style: TextStyle(color: Colors.grey, fontSize: 25.0)), // Error: Instance of Future
                );
              } else {
                return Text('Null');
              }
          }
      ),
    );
  }
}
1. Make your stream function an async* function:
Stream streamScore() async* {
  while (true) {
    await Future.delayed(Duration(seconds: 1));
    yield await getCricketScoreApi();
  }
}
2. Deal with the future
Stream<Future> streamScore() {
  ...
}
...
body: StreamBuilder<Future>(
    stream: streamScore(),
    builder: (context, snapshot){
        if(snapshot.hasData) {
          return FutureBuilder(
            future: snapshot.data!
            builder: (context, snapshot1) {
              if (snapshot.hasData) {
                return Center(child: Text(snapshot1.data!.toString()));
              } 
              return CircularProgressIndicator();
            }
          );
        } else {
          return Text('Null');
        }
    }
),

Source: link

0

You have to upgrade the dart version or just use the lower version of firebase_auth. You can use the below command:
firebase_auth: 2.0.0
First of all, upgrade to the new flutter version. Open Command Prompt and run this command.
flutter upgrade

Source: link

Recent Questions on firebase

    Programming Languages