'I'm getting the error "Another exception was thrown: You are trying to use contextless navigation without" when I run my app
Here is my code
Spacer(), // 1/6
InkWell(
onTap: () => Get.to(QuizScreen()),
child: Container(
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.all(kDefaultPadding * 0.75), // 15
decoration: BoxDecoration(
gradient: kPrimaryGradient,
borderRadius: BorderRadius.all(Radius.circular(12)),
),
child: Text(
"Lets Start Quiz",
style: Theme.of(context)
.textTheme
.button
.copyWith(color: Colors.black),
),
),
),
Spacer(flex: 2), // it will take 2/6 spaces
],
),
),
),
],
),
);
} }
Please can someoene please help me check for the cause of this r=error. I get the error when I tap the button. The project builds fine but i dont get a feedback when i tap the button
Error: Another exception was thrown: You are trying to use contextless navigation without.
Solution 1:[1]
You Need to Add GetMaterialApp In Your Main.dart file for GetX .
Thanks . Here is the Demo :
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getxpro/view/cartPage.dart';
import 'package:getxpro/view/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp( //for navigation dont forget to use GetMaterialApp
title: 'getXpro',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (context) => HomePage(),
'/cart': (context) => CartPage(),
},
);
}
}
Solution 2:[2]
Since the question lacks information such as using the Get package to handle the navigation, it looks like there is a missing Get.Key so you have to add
get.testmode=true
inside your GetMaterialApp()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tasnuva Tavasum oshin |
| Solution 2 | Extreme Geek |
