Flutter Error "Could not navigate to inital root in my app" - flutter

Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 2,632ms.
I/flutter (17581): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (17581): The following message was thrown:
I/flutter (17581): Could not navigate to initial route.
I/flutter (17581): The requested route name was: "/home"
I/flutter (17581): There was no corresponding route in the app, and therefore the initial route specified will be
I/flutter (17581): ignored and "/" will be used instead.
I/flutter (17581): ════════════════════════════════════════════════════════════════════════════════════════════════════
I just want to override the '/' route for now, '/home' need this to be my first screen that message appear. some help me, I'm the new guy to flutter
My code here
import 'package:flutter/material.dart';
import 'package:worldtime/pages/choose_location.dart';
import 'package:worldtime/pages/home.dart';
import 'package:worldtime/pages/loading.dart';
void main() => runApp(MaterialApp(
initialRoute: '/home',
routes: {
'/': (context) => Loading(),
'home': (context) => Home(),
'/location': (context) => ChooseLocation()
},
));

You mis-typed the route. You have written route as:
'home': (context) => Home(),
You need to change that to:
'/home': (context) => Home(),

Related

Navigate to same page with new data on GETX navigation

GetPage(
name: _Paths.PRODUCT_DETAILS_PAGE,
page: () => const ProductDetailsPageView(),
binding: ProductDetailsPageBinding(),
middlewares: [
ProductDetailsMiddleware(),
],
),
Navigate to ProductDetailsPage from ProductDetailsPage with some new data using GetMiddleware by parameters:
Get.toNamed(
Routes.PRODUCT_DETAILS_PAGE,
preventDuplicates: true,
parameters: {
'model': json.encode(product),
},
);
and this navigation continue by several times.
After that Navigate to back constantly with different previous data
But when I second time navigate this page an error happened like:
I/flutter (22387): The widget on which setState() or markNeedsBuild() was called was:
I/flutter (22387): Obx
I/flutter (22387): The widget which was currently being built when the offending call was made was:
I/flutter (22387): Builder

Crash after reset scenes because of focus

I am trying to make login logout system , every thing works fine
but one scene has auto focus
so when I open the following
login --> focus scene --> logout --> login --> focus scene , after will crash
there is dispose
#override
void dispose() {
_inputFocusNode.dispose();
_textController.dispose();
super.dispose();
}
here when logout:
await Navigator.of(context, rootNavigator: true)
.pushNamedAndRemoveUntil(
'/login', (Route<dynamic> route) => false,);
I run it on web (google chrome)
flutter SDK 3.3.4
Mac os
Difficult to answer with the little code snippet. Check if your routes are configured.
Example:
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => const FirstScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => const SecondScreen(),
},
Also refer to this stack overflow, if this helps;
Flutter remove all routes

Flutter build failed due to Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

Once i added the cloud_firestore: ^3.2.1 dependency, I started getting this error, I even removed this dependency, but I am still getting this error. When the dependency wasn't in my project and I was just using Firebase Auth, everything was fine.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => QuestionSectionProvider()),
ChangeNotifierProvider(create: (_) => UIHelperProvider()),
ChangeNotifierProvider(create: (_) => UserProvider())
],
child: const MedicPro()
)
);
}
I was able to solve this issue using flutter clean
Steps to resolve:
Stop the project if the project is running.
flutter clean
flutter pub get.
Run the project.

Null check operator used on a null value when using Named routes

I am getting this error after I switched to named routes where my app was working properly when using MaterialPageRoute:
main.dart:
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ClassA()),
ChangeNotifierProvider(
create: (context) => ClassB()),
],
child: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return FutureBuilder(
future: Firebase.initializeApp(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return ...
}
if (snapshot.connectionState == ConnectionState.done) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App Title',
initialRoute: '/',
routes: {
'/': (context) => Wrapper(),
'somePage/': (context) => SomePage(),
},
);
}
//else ...
return ... ;
});
}
}
The error message:
The following _CastError was thrown building Builder(dirty):
Null check operator used on a null value
The relevant error-causing widget was:
MaterialApp file:///.../lib/main.dart:40:20
When the exception was thrown, this was the stack:
#0 _WidgetsAppState._onGenerateRoute.<anonymous closure> (package:flutter/src/widgets/app.dart:1196:48)
#1 MaterialPageRoute.buildContent (package:flutter/src/material/page.dart:54:55)
#2 MaterialRouteTransitionMixin.buildPage (package:flutter/src/material/page.dart:107:27)
#3 _ModalScopeState.build.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/routes.dart:840:53)
#4 Builder.build (package:flutter/src/widgets/basic.dart:7555:48)
Flutter Doctor:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.2, on Microsoft Windows [Version 10.0.19042.867], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.52.1)
[√] Connected device (3 available)
• No issues found!
The weird thing is that the app works after multiple hot-restarts, then a hot-restart crash it.
I encountered the same situation as you did and relaunched the app solved this problem.
Not sure about the «why» but you have to change the «root» widget from the FutureBuilder to the MaterialApp registering the named routes.
Had the same code structure and the same bug as you. I made my MaterialApp as the argument to runApp and everything is fine ¯_(ツ)_/¯
You can't provide both initialRoute and '/',
Route '/' is already the initialRoute just remove the initialRoute

Hi, I am getting error between pages. Can you suggest a solution for my page?

When switching pages
  --- new GestureDetector (
                 onTap: () => Navigator.pushNamed (context, "/ lanc"), ---
My lanc page doesn't open. I'll be very happy if you suggest a solution. Thank you
main.dart --mypage--
=>
import 'arayuz/lanc.dart';
void main() {
runApp(
MaterialApp(
initialRoute: "/",
routes: {
"/": (context) => ScaffoldOge(),
"/hello": (context) => Hello(),
"/lanc": (context) => Kalp(),
},
),
);
}
--My Error--
=>
Another exception was thrown: Could not find a generator for route RouteSettings("/lanc", null) in the _WidgetsAppState.
you code isn't clear enough for me to spot the error , but i can suggest you to watch these tutorials it'll be very helpful,this by_reso_coder and this one by_filledStacks