I’m new on learning flutter and I’m trying do build my app, but I’m stuck on a simpley function. The gesture detecion does not work. I get no errors, but when i click on the button, nothing happens, I would like to move from the intro_page to home.
Can someone find the error?
import 'package:flutter/material.dart';
import 'home.dart';
class IntroPage extends StatelessWidget {
const IntroPage({super.key});
get navigator => null;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: Padding(
padding: const EdgeInsets.all(25),
child: Column(
children: [
// Abstand
const SizedBox(height: 180),
// title
const Text('Trade App',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 32,
color: Colors.white,
)),
//subtitele
const Text('Verkaufen und Kaufen',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Color.fromARGB(255, 255, 255, 255),
)),
//Abstand
const SizedBox(height: 50),
// start button
GestureDetector(
onTap: () => navigator.push(
context,
MaterialPageRoute(
builder: (context) => const Home(),
),
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.all(20),
child: const Text('Loslegen'),
),
),
],
),
),
),
);
}
}
I tried to read in several forums and watch videos, but I don’t know how to solve it
2
Answers
Yes, it’s expected !
what does this getter function do in your code :
get navigator => null;
and, in your callback you call this
navigator getter
which returnsnull
:TO FIX
You have 2 options, you can either remove this getter and use
Navigator.of(context)
, or return this navigator from your getter as the following:But, how could you reach the
context
!, so i recommend to remove this getter.I don’t understand why you created a null navigator object , instead of this you can try just use Navigator class like below