Home > Software engineering >  How to open a new screen in flutter?
How to open a new screen in flutter?

Time:07-09

What I am trying to do is open my app download screen when there is no internet connection just like youtube but I am facing this error.

lib/main.dart:5:8: Error: Not found: 'dart:js'
import 'dart:js';
       ^
lib/main.dart:34:31: Error: The argument type 'Context' can't be assigned to the parameter type 'BuildContext'.
 - 'Context' is from 'package:path/src/context.dart' ('../../.pub-cache/hosted/pub.dartlang.org/path-1.8.0/lib/src/context.dart').
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../FlutterDev/flutter/packages/flutter/lib/src/widgets/framework.dart').
          return Navigator.of(context).pushNamed('/downloads');
                              ^
Unhandled exception:

**This is my code **


    InternetConnectionChecker().checkInterval = Duration(seconds: 10);
      InternetConnectionChecker().onStatusChange.listen(
            (InternetConnectionStatus status) {
          switch (status) {
            case InternetConnectionStatus.connected:
            // ignore: avoid_print
              print('Data connection is available.');

              break;
            case InternetConnectionStatus.disconnected:
              return Navigator.of(context).pushNamed('/downloads');

              break;
          }
        },
      );

CodePudding user response:

Remove this import

import 'dart:js';

CodePudding user response:

Just remove dart:js and import 'package:flutter/material.dart'. You will not need any other thing to use context etc.

  • Related