I’m attempting to vary display on push button. However by some means the context has no Navigator because the error suggests:
Navigator operation requested with a context that doesn't embody a Navigator.
The context used to push or pop routes from the Navigator have to be that of a widget that may be a descendant of a Navigator widget.
When the exception was thrown, this was the stack:
#0 Navigator.of.<nameless closure> (package deal:flutter/src/widgets/navigator.dart:2554:9)
#1 Navigator.of (package deal:flutter/src/widgets/navigator.dart:2561:6)
#2 _MyAppState.construct.<nameless closure>.<nameless closure> (package deal:base_app/principal.dart:64:35)
#3 _InkResponseState.handleTap (package deal:flutter/src/materials/ink_well.dart:1072:21)
#4 GestureRecognizer.invokeCallback (package deal:flutter/src/gestures/recognizer.dart:253:24)
#5 TapGestureRecognizer.handleTapUp (package deal:flutter/src/gestures/faucet.dart:627:11)
#6 BaseTapGestureRecognizer._checkUp (package deal:flutter/src/gestures/faucet.dart:306:5)
#7 BaseTapGestureRecognizer.handlePrimaryPointer (package deal:flutter/src/gestures/faucet.dart:239:7)
Nonetheless, in response to this message there’s a Navigator in #0 and #1 so what’s the drawback?
Mycode:
import 'package deal:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package deal:amplify_authenticator/amplify_authenticator.dart';
import 'package deal:amplify_flutter/amplify_flutter.dart';
import 'package deal:flutter/materials.dart';
import 'package deal:base_app/add_device.dart';
import 'amplifyconfiguration.dart';
void principal() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : tremendous(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isAmplifyConfigured = false;
@override
void initState() {
tremendous.initState();
_configureAmplify();
}
void _configureAmplify() async {
strive {
await Amplify.addPlugin(AmplifyAuthCognito());
await Amplify.configure(amplifyconfig);
setState(() => _isAmplifyConfigured = true);
print('Efficiently configured');
} on Exception catch (e) {
print('Error configuring Amplify: $e');
}
}
Future<bool> isUserSignedIn() async {
last consequence = await Amplify.Auth.fetchAuthSession();
return consequence.isSignedIn;
}
@override
Widget construct(BuildContext context) {
return Authenticator(
baby: MaterialApp(
builder: Authenticator.builder(),
dwelling: _isAmplifyConfigured? FutureBuilder(
future: isUserSignedIn(),
builder: (BuildContext ctx, AsyncSnapshot snapshot) {
if (snapshot.knowledge == null) {
return const Heart(
baby: CircularProgressIndicator(),
);
} else {
return Scaffold(
floatingActionButton: FloatingActionButton(
backgroundColor: Colours.blue,
foregroundColor: Colours.white,
onPressed: () => {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => AddDevice())),
},
baby: Icon(Icons.add),
)
);
}
}): Textual content("not logged in")
),
);
}
}
It is a fundamental code of a extra advanced app however even right here it doesn’t work. I attempted a number of strategies from different posts with all the identical consequence.