现在我使用 showPerformanceOverlay
来显示 flutter 中的性能信息。但是当在真实设备上运行时,我想关闭性能 UI 而不重新安装 flutter 应用程序。是否可以启用或禁用 showPerformanceOverlay
| checkerboardOffscreenLayers
| checkerboardRasterCacheImages
在真实设备中?这是我在应用中使用的配置:
return MaterialApp(
title: 'Cruise',
theme: currentTheme,
checkerboardOffscreenLayers: true,
checkerboardRasterCacheImages: true,
showPerformanceOverlay: true,
localizationsDelegates: [
// ... app-specific localization delegate[s] here
// TODO: uncomment the line below after codegen
// AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
AppLocalizations.delegate
],
supportedLocales: [
const Locale('en', ''), // English, no country code
const Locale('ar', ''), // Arabic, no country code
const Locale.fromSubtags(languageCode: 'zh'), // Chinese *See Advanced Locales below*
// ... other locales the app supports
],
//home: HomeNew(),
home: routes.buildPage('home', null),
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<Object>(builder: (BuildContext context) {
return routes.buildPage(settings.name, settings.arguments);
});
});
答案 0 :(得分:1)
使用有状态的小部件。切换调试模式横幅的示例:
class MyApp extends StatefulWidget {
@override
createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool showDebugBanner = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: showDebugBanner,
home: Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.remove_red_eye),
onPressed: () => setState(() => showDebugBanner = !showDebugBanner),
),
),
);
}
}