Closed CripyIce closed 3 years ago
VRouter.builder
seems wrong. It is supposed to give you a context
and a child
and you must use the child
.
@lulupointu Thanks for the fast response, but can you explain a bit more? What should I change in my code to make it work?
What is BotToastInit()
?
You should replace it by (context, child) => BotToastInit(child: child)
and return that child at some point.
I removed BotToastNavigatorObserver()
from navigatorObservers
and builder: BotToastInit(),
completely, and still get an error:
Error: RangeError: Index out of range: no indices are valid: 0
at Object.throw_ [as throw] (http://localhost:54077/dart_sdk.js:5348:11)
at HTMLCollection.[dartx._get] (http://localhost:54077/dart_sdk.js:85475:70)
at Function.pushReplacement (http://localhost:54077/packages/vrouter/src/widgets/vwidget_guard.dart.lib.js:7084:128)
at vrouter_delegate.VRouterDelegate.new._updateUrl (http://localhost:54077/packages/vrouter/src/widgets/vwidget_guard.dart.lib.js:7714:48)
at _updateUrl.next (<anonymous>)
at http://localhost:54077/dart_sdk.js:39230:33
at _RootZone.runUnary (http://localhost:54077/dart_sdk.js:39087:58)
at _FutureListener.thenAwait.handleValue (http://localhost:54077/dart_sdk.js:34073:29)
at handleValueCallback (http://localhost:54077/dart_sdk.js:34633:49)
at Function._propagateToListeners (http://localhost:54077/dart_sdk.js:34671:17)
at _Future.new.[_completeWithValue] (http://localhost:54077/dart_sdk.js:34513:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:54077/dart_sdk.js:34536:35)
at Object._microtaskLoop (http://localhost:54077/dart_sdk.js:39374:13)
at _startMicrotaskLoop (http://localhost:54077/dart_sdk.js:39380:13)
at http://localhost:54077/dart_sdk.js:34887:9
Even after stopping and starting again your app?
Also do you still have "WARNING: You tried to set the url strategy several time, this should never happen. If a package that you use (other than VRouter) sets the url strategy, please use the other package."?
Yes, even after stopping and starting my app again.
And I still get this warning WARNING: You tried to set the url strategy several time, this should never happen. If a package that you use (other than VRouter) sets the url strategy, please use the other package.
even after a fresh start of my app.
Note that on iOS it seems to work fine.
Could you try to remove everything possible until you don't get the error? Then share the code
Yes of course. I have another web project and it works there perfectly. I'm comparing the code to see what is causing the issue. I will post a comment of course with updates.
With the following code it works great on web, but I still can't find what is causing the issue - maybe you could help me understand.
It seems that builder: BotToastInit()
doesn't causes the issue.
main.dart
import 'package:bot_toast/bot_toast.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:sdo_cms/remote/api_provider.dart';
import 'package:vrouter/vrouter.dart';
import 'app/config.dart';
import 'home.dart';
import 'login.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(App());
}
class App extends StatelessWidget {
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _initialization,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MyApp();
}
return SizedBox.shrink();
},
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Provider<ApiProvider>(
create: (_) => ApiProvider(),
child: VRouter(
title: "SDO CMS",
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
// mode: VRouterModes.history,
theme: ThemeData(
primaryColor: PRIMARY_COLOR,
accentColor: PRIMARY_COLOR,
visualDensity: VisualDensity.adaptivePlatformDensity,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: PRIMARY_COLOR,
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(primary: PRIMARY_COLOR),
),
textTheme: GoogleFonts.quicksandTextTheme(
Theme.of(context).textTheme,
),
),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale("fr", "FR"),
],
locale: Locale("fr", "FR"),
initialUrl: "/",
routes: [
VWidget(
path: "/",
widget: SplashPage(),
),
VWidget(
path: "/login",
widget: LoginPage(),
),
VWidget(
path: "/home",
widget: HomePage(),
),
VRouteRedirector(path: r":_(.+)", redirectTo: "/"),
],
// initialRoute: "/",
// routes: {
// "/": (context) => SplashPage(),
// "/login": (context) => LoginPage(),
// "/home": (context) => HomePage(),
// },
// onUnknownRoute: (RouteSettings settings) {
// return MaterialPageRoute<void>(
// settings: settings,
// builder: (BuildContext context) =>
// Scaffold(body: Center(child: Text("Not Found"))),
// );
// },
),
);
}
}
class SplashPage extends StatefulWidget {
@override
_SplashPageState createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
FirebaseAuth _auth = FirebaseAuth.instance;
@override
void initState() {
super.initState();
Future.delayed(Duration(seconds: 2)).then((value) =>
context.vRouter.push(_auth.currentUser == null ? "/login" : "/home"));
}
@override
Widget build(BuildContext context) {
return Container();
}
}
Oh I think I know !
Do you have the following in your index.html
:
<base href="/">
It should be inside the <head>
tag.
Tell me if this does the trick.
Also I will shit a fix for that in v1.2
so that it's no longer mandatory. However this version could not be here before a few days as I'm making some other changes
I didn't had this code <base href="/">
and after adding it in <head>
tag it seems to work fine.
Feel free to close this then if everything is working. This won't be an issue even without the tag after v1.2
anyway
Hi there, Started using this library but I can't get it to work properly. I keep getting
RangeError: Index out of range: no indices are valid: 0
error.full log:
main.dart
flutter doctor
Thanks in advance!