Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 原生工程集成flutterModule模块,在模块里集成flutter flutter_boost,程序一启动控制台输出错误。 #1997

Open
FPJack opened this issue Mar 26, 2024 · 0 comments

Comments

@FPJack
Copy link

FPJack commented Mar 26, 2024

请描述遇到的问题,以及您所期望的正确的结果

flutter: The Dart VM service is listening on http://127.0.0.1:56452/qOKg71RTivI=/
flutter: FlutterBoost_dart#boost_flutter_binding: handleAppLifecycleStateChanged AppLifecycleState.resumed
flutter: ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞═══════════════════════
The following assertion was thrown during a platform message
callback:
Invalid lifecycle state transition generated from
AppLifecycleState.resumed to AppLifecycleState.detached
(generated [AppLifecycleState.detached])
'package:flutter/src/services/binding.dart':
Failed assertion: line 317 pos 12: '(){
AppLifecycleState? starting = previousState;
for (final AppLifecycleState ending in stateChanges) {
if (!_debugVerifyLifecycleChange(starting, ending)) {
return false;
}
starting = ending;
}
return true;
}()'

Either the assertion indicates an error in the framework itself,
or we should provide substantially more information in this error
message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on
GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack:
#2 ServicesBinding._generateStateTransitions (package:flutter/src/services/binding.dart:317:12)
#3 ServicesBinding._handleLifecycleMessage (package:flutter/src/services/binding.dart:283:47)
#4 BasicMessageChannel.setMessageHandler. (package:flutter/src/services/platform_channel.dart:235:49)
#5 _DefaultBinaryMessenger.setMessageHandler. (package:flutter/src/services/binding.dart:603:35)
#6 _invoke2 (dart:ui/hooks.dart:344:13)
#7 _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:45:5)
#8 _Channel._drainStep (dart:ui/channel_buffers.dart:228:31)
(elided 4 frames from class _AssertionError and dart:async)
═════════════════════════════════════════════════════════════════

请说明如何操作会遇到上述问题

flutter_boost初始化的时候,flutter端通过FlutterError.onError = (details) {
print(details.toString());
};捕捉错误输出

在下面填入关键复现代码

iOS 端代码:
#import "GMAppDelegate.h"
#import <FlutterBoost.h>
#import <Flutter/Flutter.h>

@interface GMAppDelegate()

@EnD
@implementation GMAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
    {
    FlutterBoostSetupOptions
    options = [FlutterBoostSetupOptions createDefault];
    options.dartEntryPointArgs = @[ @"I'm from IOS!", @"--for-test" ];
    [[FlutterBoost instance] setup:application delegate:self callback:^(FlutterEngine *engine) {

     } options: options];
    

    return YES;
    }

  • (void)popRoute:(FlutterBoostRouteOptions *)options {

}

  • (void)pushFlutterRoute:(FlutterBoostRouteOptions *)options {

}

  • (void)pushNativeRoute:(NSString *)pageName arguments:(NSDictionary *)arguments {

}

@EnD

flutter 端代码:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
class CustomFlutterBinding extends WidgetsFlutterBinding
with BoostFlutterBinding {}
void main() {
FlutterError.onError = (details) {
print(details.toString());
};
CustomFlutterBinding();
return runZonedGuarded(() => const MyApp(), (error, stack) {
print(error.toString());
print(stack.toString());
});
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@OverRide
State createState() => _MyAppState();
}

class MyAppState extends State {
static Map<String, FlutterBoostRouteFactory> routerMap = {
'homepage': (settings, uniqueId) {
return PageRouteBuilder(
settings: settings,
pageBuilder: (
, __, ___) => MyHomePage(title: 'title'));
},
};

Route? routeFactory(RouteSettings settings, String? uniqueId) {
FlutterBoostRouteFactory? func = routerMap[settings.name!];
if (func == null) {
return null;
}
return func(settings, uniqueId);
}

@OverRide
Widget build(BuildContext context) {
return FlutterBoostApp(routeFactory,
// 如果自定了appBuilder,需要将传入的参数添加到widget层次结构中去,
// 否则会导致FluttBoost初始化失败。
appBuilder: (child) => MaterialApp(
home: child,
));
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;

@OverRide
State createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
int _counter = 0;

void _incrementCounter() {
setState(() {
_counter++;
});
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}

错误输出是在 FlutterError.onError = (details) {
print(details.toString());
};里面打印的

复现的平台

Both

Flutter SDK版本

3.19.0

FlutterBoost版本

5.0.1

是否延迟初始化FlutterBoost

No

解决方案

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant