-1

i have the NoSuchMethodError by simulation my App. NoSuchMethodError (NoSuchMethodError: The method '>=' was called on null. Receiver: null Tried calling: >=(55)) The Error is schowing when I simulation my app.

Can someone help me?

my full code in this file:

class GameEN extends StatefulWidget {
  //Game({Key key}) : super(key: key);
  @override
  _GameENState createState() => _GameENState();
}

class _GameENState extends State<GameEN> {
  int _counterK;
  int _pktK;


  @override
  void initState() {
    _subscription = 
    super.initState();
    _loadCounterK();     
  }

  @override
  void dispose() {
    _subscription.cancel();
    super.dispose();
  }          

//Loading counter value on start (load)
  _loadCounterK() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      _counterK = (prefs.getInt('counterK') ?? 1);
      _pktK = (prefs.getInt('pktK') ?? 0);
      print(Text("Load number is: $_counterK"));
      print(Text("Load pkt is: $_pktK"));
    });
  }

  @override
  Widget build(BuildContext context) {
    return new WillPopScope(
        onWillPop: () async => false,
        child: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.white,
              centerTitle: true,
              title: Text(
                'ToolQuiz',
                style: TextStyle(
                  fontStyle: FontStyle.italic,
                  color: Colors.black,
                ),
              ),
              actions: <Widget>[
                Padding(
                  padding: EdgeInsets.only(right: 15.0),
                  child: IconButton(
                      padding: EdgeInsets.all(0),
                      icon: Icon(
                        Icons.settings,
                        color: Colors.black,
                      ),
                      onPressed: () {
                        Navigator.push(
                          context,
                          PageRouteBuilder(
                            pageBuilder: (context, animation1, animation2) {
                              return Einstellungen();
                            },
                          ),
                        );
                      }),
                )
              ],
            ),
            body: Center(
                child: Container(
              decoration: BoxDecoration(),
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[

                    //Küchenutensilien
                    
                    GestureDetector(
                        onTap: () {
                          _interstitialAd.show();

                          _interstitialAd.dispose();
                          // _incrementCounterRightAnsK();
                          Navigator.push(
                            context,
                            PageRouteBuilder(
                              pageBuilder: (context, animation1, animation2) {
                                if (56 <= _counterK)
                                  return KuechenutensilienEnd();
                                else
                                  return KuechenutensilienStart();
                              },
                              transitionsBuilder:
                                  (context, animation1, animation2, child) {
                                return FadeTransition(
                                  opacity: animation1,
                                  child: child,
                                );
                              },
                              transitionDuration: Duration(milliseconds: 500),
                            ),
                          );
                        },
                        child: Container(
                            decoration: BoxDecoration(
                                gradient: LinearGradient(
                                  colors: [
                                    Colors.brown[600],
                                    Colors.brown[700]
                                  ],
                                  begin: Alignment.bottomLeft,
                                  end: Alignment.topRight,
                                ),
                                border:
                                    Border.all(width: 2, color: Colors.black54),
                                borderRadius: const BorderRadius.all(
                                    const Radius.circular(20))),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                              children: <Widget>[
                                Container(
                                  child: Column(
                                    children: <Widget>[
                                      Container(
                                        alignment: Alignment.center,
                                        child: Text('Küchenutensilien',
                                            style: Theme.of(context)
                                                .textTheme
                                                .headline5
                                                .copyWith(color: Colors.black)),
                                      ),
                                      Container(
                                        alignment: Alignment.center,
                                        child: Text(
                                          _pktK.toString() + ' ' + 'Punkte',
                                        ),
                                      ),
                                      Container(
                                        alignment: Alignment.center,
                                        child: Text(() {
                                          if (_counterK >= 55) {
                                            return 'Level ' + '55' + '/55';
                                          }
                                          return 'Level ' +
                                              _counterK.toString() +
                                              '/55';
                                        }()),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ))),                      
           
                  ],
                ),
              ),
            ))));
  }
}

The error is showing me by all: if....>= I dont find my problem :(

Thanks for your help

Bruno
  • 79
  • 1
  • 8
  • Can't reproduce the error. The code works fine. Can you show the whole code maybe you're not looking at the good line. IDE and some error messages can be missleading. – CookieThief May 31 '21 at 21:58
  • Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt Jun 01 '21 at 07:40
  • 1
    Also, please use the latest stable version of Dart/Flutter, your error is only possible if you are using an outdated version. – nvoigt Jun 01 '21 at 07:41
  • Thanks nvoigt for dir your help – Bruno Jun 06 '21 at 21:12

2 Answers2

0

Please make sure that _counterK is properly initialized, do so by initializing it when declaring it Int _counterK = 0

Extreme Geek
  • 574
  • 5
  • 13
  • Is that a problem when the int is using for SharedPreference? The value of the int are changing. – Bruno Jun 01 '21 at 07:06
0

I solve the problem by changing to the flutter stable channel

Bruno
  • 79
  • 1
  • 8