【问题标题】:White Screen Appears When Keyboard Pop Up键盘弹出时出现白屏
【发布时间】:2019-04-16 13:59:08
【问题描述】:

我是 Flutter 的新手。我有一个问题,但我不知道如何调试来解决这个问题。我尝试建立一个登录/注册页面。但是当我尝试在文本字段中输入值时,它只会在软键出现时显示白屏。不知道为什么会这样。你能帮助指导我如何解决这个问题吗?提前谢谢你。

]2

main.dart

    import 'package:flutter/material.dart';
import 'sign_in.dart';
import 'sign_up.dart';
import 'reset_password.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.red,
        accentColor: Colors.redAccent,
      ),
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(
                  child: Text('Sign In'),
                ),
                Tab(
                  child: Text('Sign Up'),
                ),
                Tab(
                  child: Text('Reset Password'),
                ),
              ], indicatorColor: Colors.white,
            ),
          ),
          body: TabBarView(
            children: [
              SignIn(),
              SignUp(),
              ResetPassword(),
            ],
          ),
        ),
      ),
    );
  }
}

sign_in.dart

import 'package:flutter/material.dart';

class SignIn extends StatefulWidget {
  _SignInState createState() => _SignInState();
}

class _SignInState extends State<SignIn> {
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(20.0),
        child: Form(
            child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            TextFormField(
              decoration: InputDecoration(labelText: 'Email'),
            ),
            SizedBox(height: 20.0),
            TextFormField(
              decoration: InputDecoration(labelText: 'Password'),
              obscureText: true,
            ),
            SizedBox(height: 20.0),
            RaisedButton(
              color: Colors.red,
              child: Text('Sign In',
                  style: TextStyle(fontSize: 15.0, color: Colors.white)),
              onPressed: validateAndSave,
            ),
          ],
        )),
      ),
    );
  }
}

void validateAndSave() {}

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    如果你们遇到同样的问题,请试试这个solution。这个对我有用。谢谢。

    【讨论】:

      【解决方案2】:

      试试这个代码.. 去掉这种方式来定义..

       void main() => runApp(MaterialApp(
        debugShowCheckedModeBanner: false,
        home: MyApp(),
      ));
      

      试试这个方法,我现在测试是有效的。

      class TestApp extends StatelessWidget{
      @override
      Widget build(BuildContext context) {
      return MaterialApp(
      home: TabViewDemo(),
      );
      }
      
      }
      

      然后..

       void main() {
       runApp(TestApp());
      

      这段代码..

       class TabViewDemo extends StatefulWidget {
       @override
      _MyAppState createState() => _MyAppState();
      }
      
      class _MyAppState extends State<TabViewDemo> {
      // This widget is the root of your application.
       @override
      Widget build(BuildContext context) {
      return MaterialApp(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.red,
          accentColor: Colors.redAccent,
        ),
        home: DefaultTabController(
          length: 3,
          child: Scaffold(
            appBar: AppBar(
              bottom: TabBar(
                tabs: [
                  Tab(
                    child: Text('Sign In'),
                  ),
                  Tab(
                    child: Text('Sign Up'),
                  ),
                  Tab(
                    child: Text('Reset Password'),
                  ),
                ],
                indicatorColor: Colors.white,
              ),
            ),
            body: TabBarView(
              children: [
                SignIn(),
              ],
            ),
          ),
        ),
      );
      }
      }
      

      【讨论】:

      • 喂。感谢您的答复。我已将 main.dart 更改为无状态,但仍然没有成功。还有什么建议吗?
      • 我会尝试相同的代码,但我不会遇到任何问题。如果你需要,那么我给出完整的代码..
      • 什么?因此,当您尝试在 textformfield 中输入值时,您不会得到如上图所示的结果?请给我完整的代码
      猜你喜欢
      • 2011-02-03
      • 2021-01-16
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 2011-01-30
      • 2018-06-28
      • 2012-07-25
      • 2018-07-26
      相关资源
      最近更新 更多