当我在 Android 模拟器上启动应用程序并尝试使用虚拟键盘时,它立即关闭,并且我在调试控制台上看到以下消息:
D/InputConnectionAdaptor( 5956): The input method toggled cursor monitoring on
每当我尝试打开键盘时,应用程序似乎都会重新启动,因为我看到如下消息:
I/flutter ( 5956): isAuth is false and we are in authentication page
D/InputConnectionAdaptor( 5956): The input method toggled cursor monitoring on
2
I/flutter ( 5956): isAuth is false and we are in authentication page
D/InputConnectionAdaptor( 5956): The input method toggled cursor monitoring on
2
I/flutter ( 5956): isAuth is false and we are in authentication page
这是我的
main.dart
文件,如果您认为我添加更多代码有帮助,请告诉我:
void main() {
WidgetsFlutterBinding.ensureInitialized();
Get.put(MenuController());
Get.put(NavigationController());
Get.put(AuthController());
Get.put(AuthCard);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
AuthController.instance.tryAutoLogin();
return GetMaterialApp(
// initialRoute: AuthController.instance.isAuth
// ? rootRoute
// : authenticationScreenRoute,
unknownRoute: GetPage(
name: '/not-found',
page: () => PageNotFound(),
transition: Transition.fadeIn),
getPages: [
GetPage(
name: rootRoute,
page: () {
return SiteLayout();
}),
GetPage(
name: authenticationScreenRoute,
page: () => const AuthenticationScreen()),
GetPage(name: homeScreenRoute, page: () => const HomeScreen()),
],
debugShowCheckedModeBanner: false,
title: 'BasicCode',
theme: ThemeData(
scaffoldBackgroundColor: light,
textTheme: GoogleFonts.mulishTextTheme(Theme.of(context).textTheme)
.apply(bodyColor: Colors.black),
pageTransitionsTheme: const PageTransitionsTheme(builders: {
TargetPlatform.iOS: FadeUpwardsPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
}),
primarySwatch: Colors.blue,
),
// home: AuthController.instance.isAuth
home: Obx(()=>
AuthController.instance.isAuth
? SiteLayout()
: const AuthenticationScreen(),
),
);
}
}
我也尝试使用我的 Android 手机,但遇到了相同的错误和行为。
对我来说,解决方案是
autofocus: true,