颤动:堆叠 - 幕后 - TextFormField - 焦点问题

时间:2018-05-04 16:30:32

标签: flutter

我有一堆Offstage Widgets列表。 这些Offstage小部件中的每一个都引用MaterialApp来显示表单。 每个表单都包含几个TextFormFields。

我遇到的问题是第一个和第二个Offstage项TextFormFields永远不会得到焦点(当然考虑正确的后台:索引)。

为了使它工作,如果我把第一个Offstage放到第三个位置(因此在顶部),一切正常。

这很可能来自Stack的概念或来自Offstage。

有没有办法强制等同于" z-index "? 我也试过使用IndexedStack但结果是一样的。

除了舞台外,我应该使用其他东西吗?

非常感谢你的帮助。

以下是代码:

Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Color(0xF4FFFFFF),
      bottomNavigationBar: new Theme(
        data: Theme.of(context).copyWith(
              canvasColor: Colors.amber[700],
              primaryColor: Colors.white,
              textTheme: Theme
                  .of(context)
                  .textTheme
                  .copyWith(caption: new TextStyle(color: Colors.grey[800])),
            ),
        child: new BottomNavigationBar(
            iconSize: 8.0,
            currentIndex: index,
            onTap: (int index) {
              setState(() {
                this.index = index;
              });
            },
             type: BottomNavigationBarType.fixed,
            items: <BottomNavigationBarItem>[
                new BottomNavigationBarItem(
                  title: new Text('Sign In',
                      style: new TextStyle(fontSize: 20.0)),
                  icon: new Container(height: 8.0),
                ),
                new BottomNavigationBarItem(
                  title: new Text('Register',
                      style: new TextStyle(fontSize: 20.0)),
                  icon: new Text('No account yet',
                      style: new TextStyle(fontSize: 10.0)),
                ),
                new BottomNavigationBarItem(
                  title: new Text('lost password',
                      style: new TextStyle(fontSize: 12.0)),
                  icon: new Container(height: 8.0),
                ),
              ]),
      ),
      body: new SafeArea(
        top: false,
        bottom: false,
        child: new Stack(children: <Widget>[
          new Offstage(
              offstage: index != 0,
              child: new MaterialApp(
                home: new LoginForm(),
                debugShowCheckedModeBanner: false,
              )),
          new Offstage(
            offstage: index != 1,
            child: new MaterialApp(
              home: new RegisterForm(),
              debugShowCheckedModeBanner: false,
            ),
          ),
          new Offstage(
            offstage: index != 2,
            child: new MaterialApp(
              home: new LostPasswordForm(),
              debugShowCheckedModeBanner: false,
            ),
          ),
        ]),
      ),
    );
  }

1 个答案:

答案 0 :(得分:0)

在试图找到类似问题的解决方案时偶然发现了这个问题。您可能已经继续前进,但是我很确定这与https://github.com/flutter/flutter/issues/17098中描述的问题相同。希望这对以后的人有所帮助。

相关问题