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;
}
},
);
2
Answers
Remove this import
Just remove dart:js and import ‘package:flutter/material.dart’. You will not need any other thing to use context etc.