Home > Software design >  Black screen after Navigation.push
Black screen after Navigation.push

Time:09-28

I'm trying to change screen on a flutter android application.

I have a Navigator.push(context,MaterialPageRoute(builder: (context) => const Dashboard(title: 'dashboard'))); within a void function in my main.dart file.

This is the dashboard.dart file where i have the other page to access

import 'package:arboapp/main.dart';

import 'main.dart';
void main() {
  runApp(MaterialApp(home: Register()));
}
class Register extends StatelessWidget {
  Register({super.key});
  @override
  Widget build(BuildContext context) {
    Widget title = Row(children: [
      Container(
        child: TextButton(onPressed: () {  },
            child: Text("culo")),
      )]);
    return MaterialApp(
        title: 'Flutter Demo',
        home: Scaffold(
            body: ListView(
                children: [title])),
        theme: ThemeData(
          scaffoldBackgroundColor: const Color(0xfffffffff),
          primarySwatch: Colors.deepOrange,
        ));
  }
}

class _DashboardState extends State<Dashboard> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Although when the function tries to switch page, it goes to a black screen (I'm still able to go back to the previous page with navigation buttons). I tried to look online but this case seems different as I have no error msg in the console and even trying to use a different method to switch screen (different navigator.push) the result is the same.

CodePudding user response:

this happens when you don't set a Scaffold to the widget, the widget that you're trying to navigate to is open but a Scaffold is missing so make sure your Dashboard widget have a Scaffold

  • Related