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?
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!!"),),
);
}
}
This worked for me:
Navigator.pushAndRemoveUntil(context,
MaterialPageRoute(builder: (context) => HomePage()), (r) => false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With