flutter_boost icon indicating copy to clipboard operation
flutter_boost copied to clipboard

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

Open FPJack opened this issue 1 year ago • 1 comments

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

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()<FlutterBoostDelegate>

@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<MyApp> createState() => _MyAppState(); }

class MyAppState extends State<MyApp> { 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<MyHomePage> createState() => _MyHomePageState(); }

class _MyHomePageState extends State<MyHomePage> { 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: <Widget>[ 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

解决方案

FPJack avatar Mar 26 '24 10:03 FPJack

解决了吗

kavin-zhihua avatar Jan 20 '25 05:01 kavin-zhihua