首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到Material Widget文本字段widget需要material widget祖先(Flutter)

未找到Material Widget文本字段widget需要material widget祖先(Flutter)
EN

Stack Overflow用户
提问于 2021-02-15 23:44:37
回答 1查看 887关注 0票数 2

嗨,我正试图在flutter中建立一个登录屏幕,但当我打开它时,我得到了下面的错误。

未找到material微件文本字段微件需要material微件祖先

代码语言:javascript
复制
class HomePage extends StatelessWidget {
  final TextEditingController emailController = TextEditingController();
  final TextEditingController passwordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        Provider<AuthenticationService>(
          create: (_) => AuthenticationService(FirebaseAuth.instance),
        ),
        StreamProvider(
          create: (context) =>
          context.read<AuthenticationService>().authStateChanges,
        ),
      ],
      child:MaterialApp(
        home: SingleChildScrollView(
            child: Container(
              child: Column(
                children: <Widget>[
                  Container(
                    height: 400,
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            image: AssetImage('assets/images/loginHeader.png'),
                            fit: BoxFit.fill)),
                    child: Stack(
                      children: <Widget>[],
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(30.0),
                    child: Column(
                      children: <Widget>[
                        FadeAnimation(
                            1.8,
                            Container(
                              padding: EdgeInsets.all(5),
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(10),
                                  boxShadow: [
                                    BoxShadow(
                                        color:
                                        Color.fromRGBO(143, 148, 251, .2),
                                        blurRadius: 20.0,
                                        offset: Offset(0, 10))
                                  ]),
                              child: Column(
                                children: <Widget>[
                                  Container(
                                    padding: EdgeInsets.all(8.0),
                                    decoration: BoxDecoration(
                                        border: Border(
                                            bottom: BorderSide(
                                                color: Colors.grey[100]))),
                                    child: TextField(
                                      controller: emailController,
                                      decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "Email or Phone number",
                                          hintStyle: TextStyle(
                                              color: Colors.grey[400])),
                                    ),
                                  ),
                                  Container(
                                    padding: EdgeInsets.all(8.0),
                                    child: TextField(
                                      controller: passwordController,
                                      obscureText: true,
                                      decoration: InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "Password",
                                          hintStyle: TextStyle(
                                              color: Colors.grey[400])),
                                    ),
                                  )
                                ],
                              ),
                            )),
                        SizedBox(
                          height: 30,
                        ),
                        RaisedButton(
                          padding:
                          EdgeInsets.only(left: 100, right: 100, top: 20, bottom: 20),
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(28.0),
                              side: BorderSide(color: Colors.red)),
                          onPressed: () {
                            gotoPatientList(BuildContext context) {
                              Navigator.push(
                                context,
                                MaterialPageRoute(builder: (context) =>PatientList()),
                              );
                            }
                            context.read<AuthenticationService>().signIn(
                              email: emailController.text.trim(),
                              password: passwordController.text.trim(),
                            );
                            gotoPatientList(context);
                          },
                          color: Color.fromRGBO(214, 0, 27,1),
                          textColor: Colors.white,
                          child: Text("Login".toUpperCase(),
                              style: TextStyle(fontSize: 14)),
                        ),
                         Padding(padding:EdgeInsets.only(top: 15),

                  ),
                        ClipOval(
                          child: RaisedButton(
                            onPressed: () {
                              gotoForgotPassword(BuildContext context) {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) =>ForgotPassword()),
                                );
                              }
                              gotoForgotPassword(context);
                            },
                            child: Text("Forgot Password"),
                            textColor: Colors.white,
                            color:Color.fromRGBO(214, 0, 27, 1),
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
    );
  }
}

在材质设计中,大多数小部件概念上都打印在flutter材质库中的一张材质上,该材质由渲染墨水飞溅的材质小部件表示

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-16 00:28:20

在生成器中包装SingleChildScrollView:

代码语言:javascript
复制
Builder(
builder: (context) => SingleChildScrollView......

这是因为您使用的上下文不是MaterialApp的子级。

例如,更好的解决方案是将MaterialApp放在小部件MyApp中,并使用HomePage小部件作为MaterialApp的主页。还将主体包装在脚手架内(正文: SingleChild... )。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66211033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档