4

I'm writing a Flutter app (Kinda a beginner here). Here is my code.
main.dart

import 'package:flutter/material.dart';
import 'package:flutter_app_timer/helpers/constants.dart';

void main() => runApp(ContactApp());

class ContactApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: appTitle,
      theme: new ThemeData(
        primaryColor: appColor,
      ),
    );
  }

}  

constants.dart

import 'package:flutter/material.dart';

Color appColor = Color.fromRGBO(58, 66, 86, 1.0);

const appTitle = "Contact App";  

When I run it in emulator, I get below exception message.

I/flutter ( 7381): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 7381): The following assertion was thrown building IconTheme(IconThemeData#2abdc(color:
I/flutter ( 7381): Color(0xdd000000))):
I/flutter ( 7381): Could not find a generator for route RouteSettings("/", null) in the _WidgetsAppState.

Do I need to add Navigator in main.dart? How can I fix this?

Ajay Kulkarni
  • 2,900
  • 13
  • 48
  • 97

2 Answers2

4

You must have to use a property home or initialRoute to navigate to your initial screen to display to the users.

So, just add a home Property like, inside your MaterialApp

return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: appTitle,
      theme: new ThemeData(
        primaryColor: appColor,
      ),
      home: TestPage ()
    );

Create a screen or page to display to the users as following,

class TestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(child: Text("Hello World!!"),),
    );
  }
}
Jay Mungara
  • 6,663
  • 2
  • 27
  • 49
2

This worked for me:

Navigator.pushAndRemoveUntil(context,
            MaterialPageRoute(builder: (context) => HomePage()), (r) => false);
Pedro R.
  • 643
  • 6
  • 10