You are trying to use contextless navigation without a GetMaterialApp or Get.key. If you are testing your app, you can use: [Get.testMode = true], or if you are running your app on a physical device or emulator, you must exchange your [MaterialApp] for a [GetMaterialApp].
This is the error that i get when i press on the button. How can i fix this error and make the button work.
The code:
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:hetmaantje/constants.dart';
import 'package:hetmaantje/quiz_screen.dart';
class welcome_screen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
SvgPicture.asset("assets/icons/bg.svg", fit: BoxFit.fill),
SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Spacer(flex: 2), //2/6
Text(
"Let's Play Quiz,",
style: Theme.of(context).textTheme.headline4?.copyWith(
color: Colors.pink.shade100, fontWeight: FontWeight.bold),
),
Text("Enter your informations below"),
Spacer(), // 1/6
TextField(
decoration: InputDecoration(
filled: true,
fillColor: Color(0xFF1C2341),
hintText: "Full Name",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
),
),
Spacer(), // 1/6
InkWell(
onTap: () => Get.to(quiz_screen()),
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
],
),
),
),
],
),
);
}
}
```
CodePudding user response:
In your main.dart
file, replace MaterialApp
with GetMaterialApp
@override
Widget build(BuildContext context) {
return GetMaterialApp(
//
);
}
Check Step 1 of Getx Package documentation Documentation Link