Issue running app on release/profile mode in flutter web
The following error appears when I run the web application in release / profile mode:
NoSuchMethodError: method not found: 'pendingResult' on null
js_primitives.dart:47 at _GetItImplementation.call$1$3$instanceName$param1$param2 (http://localhost:51996/main.dart.js:146471:30)
js_primitives.dart:47 at _GetItImplementation.call$3$instanceName$param1$param2 (http://localhost:51996/main.dart.js:146487:19)
js_primitives.dart:47 at StackedLocator.call$1$0 (http://localhost:51996/main.dart.js:153365:27)
js_primitives.dart:47 at StartupView_build_closure1.call$0 (http://localhost:51996/main.dart.js:81285:17)
js_primitives.dart:47 at ViewModelBuilder.viewModelBuilder$0 (http://localhost:51996/main.dart.js:153545:36)
js_primitives.dart:47 at _ViewModelBuilderState._createViewModel$0 (http://localhost:51996/main.dart.js:153559:36)
js_primitives.dart:47 at _ViewModelBuilderState.initState$0 (http://localhost:51996/main.dart.js:153553:15)
js_primitives.dart:47 at StatefulElement._firstBuild$0 (http://localhost:51996/main.dart.js:129606:51)
js_primitives.dart:47 at StatefulElement.mount$2 (http://localhost:51996/main.dart.js:129482:12)
js_primitives.dart:47 at StatelessElement.inflateWidget$2 (http://localhost:51996/main.dart.js:129249:16)
If I change this code in app.locator.dart:
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import '';
import '../services/api_service.dart';
import '../services/authentication_service.dart';
import '../services/shared_preferences_service.dart';
final locator = StackedLocator.instance;
Future setupLocator() async {
locator.registerLazySingleton(() => NavigationService());
locator.registerLazySingleton(() => AuthenticationService());
locator.registerLazySingleton(() => ApiService());
final sharedPreferencesService = await SharedPreferencesService.getInstance();
locator.registerSingleton(sharedPreferencesService);
}
For this one:
import 'package:get_it/get_it.dart';
import 'package:stacked_services/stacked_services.dart';
import '../services/api_service.dart';
import '../services/authentication_service.dart';
import '../services/shared_preferences_service.dart';
final locator = GetIt.instance;
Future setupLocator() async {
locator.registerLazySingleton(() => NavigationService());
locator.registerLazySingleton(() => AuthenticationService());
locator.registerLazySingleton(() => ApiService());
final sharedPreferencesService = await SharedPreferencesService.getInstance();
locator.registerSingleton(sharedPreferencesService);
}
Everything works fine.
Apparently the problem is in StackedLocator.instance.
I was trying to figure out whats going on for 1h now. Thanks @katusiky !
That's a weird bug because in debug mode everything works?!
Faced the same problem and had to re-make my project from scratch component by component to see what breaks it. Then realized that it was Stacked causing the break. Then I saw this :(( @katusiky you are a gem, thanks for the fix!
thanks @katusiky!
Unfortunately same error occurs when using stacked_themes, cost me the whole weekend to find that out.
Here is actually final locator = GetIt.asNewInstance(); used, so I'm not sure if it's 100% related to StackedLocator.instance.
I got here the code to reproduce it, just played around a bit with the combination of provider, get_it, stacked and stacked_themes: https://github.com/BenPoell/get_it_provider
This is not solving the issue ViewModelBuilder<LoginViewModel>.reactive(
viewModelBuilder: () => locator.get<LoginViewModel>(),
builder: (context, model, child) {
return Container(
margin: const EdgeInsets.only(top: 50),
child: Column(
children: <Widget>[
Padding(
padding:
const EdgeInsets.only(left: 18.0, right: 18.0, top: 0),
child: Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(20.0)),
child: SizedBox(
width: double.infinity,
height: 60,
child: FlatButton(
onPressed: () {
_showModalBottomSheet(context);
},
color: Colors.blue,
child: Text(
'Create Account',
style: Theme.of(context)
.textTheme
.headline6!
.copyWith(color: Colors.white),
),
),
),
),
),
Container(
padding:
const EdgeInsets.only(left: 18.0, right: 18.0, top: 20),
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(10.0)),
child: SizedBox(
width: double.infinity,
height: 60,
child: OutlineButton(
color: Colors.blue,
child: Text(
'Sign in',
style: Theme.of(context)
.textTheme
.headline6!
.copyWith(color: Colors.blue),
),
onPressed: () {
_showModalBottomSheet(context);
},
),
),
),
],
),
);
})
and I have this
@StackedApp(
routes: [
MaterialRoute(page: StartUpView, initial: true),
MaterialRoute(page: DashboardView),
MaterialRoute(page: SignUpFormView),
MaterialRoute(page: BusinessHomeView),
MaterialRoute(page: LoginView),
],
dependencies: [
LazySingleton(classType: NavigationService),
LazySingleton(classType: LoginViewModel)
],
)
class AppSetup {
/** Serves no purpose besides having an annotation attached to it */
}