弹出键盘时出现白屏

时间:2019-04-16 13:59:09

标签: dart flutter

我是新手。我遇到问题,但不确定如何调试以解决问题。我尝试建立一个登录/注册页面。但是,当我尝试在文本字段中输入值时,出现软键时它将仅显示白屏。不知道为什么会这样。您能帮我指导如何解决此问题吗?预先谢谢你。

Before[![After] 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() {}

2 个答案:

答案 0 :(得分:0)

尝试此代码。 删除这种定义..

的方法
 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(),
        ],
      ),
    ),
  ),
);
}
}

答案 1 :(得分:0)

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