键盘弹出时出现白屏

问题描述 投票:0回答:2

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

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() {}
dart flutter
2个回答
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(),
        ],
      ),
    ),
  ),
);
}
}

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.