小编Nul*_*ter的帖子

Flutter:BottomNavigationBar在选项卡更改时重建页面

我在Flutter中的BottomNavigationBar有问题。如果要更改标签,我想让页面保持活动状态。

这是我的实现

底部导航

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int _currentIndex = 0;
  List<Widget> _children;
  final Key keyOne = PageStorageKey("IndexTabWidget");

  @override
  void initState() {
    _children = [
      IndexTabWidget(key: keyOne),
      PlaceholderWidget(Colors.green),
      NewsListWidget(),
      ShopsTabWidget(),
      PlaceholderWidget(Colors.blue),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(MyApp.appName),
        textTheme: Theme.of(context).textTheme.apply(
              bodyColor: Colors.black,
              displayColor: Colors.blue,
            ),
      ),
      body: _children[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: onTabTapped,
        key: IHGApp.globalKey,
        fixedColor: Colors.green,
        type: BottomNavigationBarType.fixed,
        currentIndex: …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-layout

19
推荐指数
3
解决办法
7468
查看次数

在Android中调试Kotlins协同程序

是否有可能在Android中调试协同程序?当我尝试调试此代码段时:

runBlocking {
        try {
            async(CommonPool) {
                showLoadingIndicator()
                val a = loadData().await()
                hideLoadingIndicator()
            }
        } catch (e: Exception) {
            Log.e("lala", "exception " + e.toString())
        }
}
Run Code Online (Sandbox Code Playgroud)

val a有以下消息: Cannot find local variable: name = a

在我的应用程序中,我正在设置coroutines调试的属性,如下所示:

System.setProperty("kotlinx.coroutines.debug", if (BuildConfig.DEBUG) "on" else "off")
Run Code Online (Sandbox Code Playgroud)

还是行不通.现在我不知道在使用协同程序时如何使用调试器.愿你们帮帮我吧?

提前致谢

阿尔班

debugging android kotlinx.coroutines

6
推荐指数
1
解决办法
1424
查看次数

iOS上单一页面的Flutter设备方向

我想以横向模式在Flutter应用程序中显示单个页面。其他所有屏幕均应以纵向模式显示。

我找到了以下代码片段:

在我的main.dart中

SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]).then((_) {
    runApp(new IHGApp());
  });
Run Code Online (Sandbox Code Playgroud)

这将以纵向模式启动该应用程序。所以我有要在横向模式下显示的屏幕,这是我在那里使用的代码:

@override
  void initState() {
    super.initState();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeRight,
      DeviceOrientation.landscapeLeft,
    ]);
  }


  @override
  void dispose() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
    super.dispose();
  }
Run Code Online (Sandbox Code Playgroud)

这适用于Android。

在iOS上,似乎无法对单个页面强制使用横向模式。

https://github.com/flutter/flutter/issues/13238

在本文中,我找到了此问题的问题。鲁rod的提到了如何解决这个问题。

“我解决了创建一个小型平台通道的问题,该通道调用此代码以在调用setPreferredOrientations之前立即切换到肖像:”

[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)

和对应的代码切换到风景

[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud)

如何在我的应用程序中实现呢?

landscape ios landscape-portrait flutter

5
推荐指数
1
解决办法
585
查看次数