栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Flutter中使用CircularProgressIndicator

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Flutter中使用CircularProgressIndicator

好的,首先您必须稍微更改代码。

从更改

Stateless
Stateful
来管理小部件的状态,并放置一个名为的全局变量
isLoading
。您可以使用该变量,
isLoading
在按下按钮时将其设置为true,在按钮
isLoading
完成后将其设置为false。

在您的

build
方法内添加一个验证,以在
isLoading
为true 时显示循环进度,否则显示您的字段。

代码示例在这里:

    class ForgotPasswordScreen extends StatefulWidget {      @override      ForgotPasswordScreenState createState() {        return new ForgotPasswordScreenState();      }    }    class ForgotPasswordScreenState extends State<ForgotPasswordScreen> {      final emailController = new TextEditingController();      final authHandler = new Auth();      bool isLoading = false;      @override      Widget build(BuildContext context) {        return new Scaffold( body: Container(     height: MediaQuery.of(context).size.height,     decoration: BoxDecoration(       color: Colors.white,     ),     child: isLoading         ? Center(  child: CircularProgressIndicator(),)         : new Column(  crossAxisAlignment: CrossAxisAlignment.center,  mainAxisSize: MainAxisSize.max,  mainAxisAlignment: MainAxisAlignment.center,  children: <Widget>[    new Row(      children: <Widget>[        new Expanded(          child: new Padding( padding: const EdgeInsets.only(left: 40.0), child: new Text(   "EMAIL",   style: TextStyle(     fontWeight: FontWeight.bold,     color: Colors.redAccent,     fontSize: 15.0,   ), ),          ),        ),      ],    ),    new Container(      width: MediaQuery.of(context).size.width,      margin: const EdgeInsets.only(          left: 40.0, right: 40.0, top: 10.0),      alignment: Alignment.center,      decoration: BoxDecoration(        border: Border(          bottom: BorderSide(   color: Colors.redAccent,   width: 0.5,   style: BorderStyle.solid),        ),      ),      padding: const EdgeInsets.only(left: 0.0, right: 10.0),      child: new Row(        crossAxisAlignment: CrossAxisAlignment.center,        mainAxisAlignment: MainAxisAlignment.start,        children: <Widget>[          new Expanded( child: TextField(   controller: emailController,   textAlign: TextAlign.left,   decoration: InputDecoration(     border: InputBorder.none,     hintText: 'PLEASE ENTER YOUR EMAIL',     hintStyle: TextStyle(color: Colors.grey),   ), ),          ),        ],      ),    ),    Divider(      height: 24.0,    ),    new Container(      width: MediaQuery.of(context).size.width,      margin: const EdgeInsets.only(          left: 30.0, right: 30.0, top: 20.0),      alignment: Alignment.center,      child: new Row(        children: <Widget>[          new Expanded( child: new FlatButton(   shape: new RoundedRectangleBorder(     borderRadius: new BorderRadius.circular(30.0),   ),   color: Colors.redAccent,   onPressed: () {     setState(() {       isLoading = true;     });     authHandler         .sendPasswordResetEmail(  emailController.text)         .then((void nothing) {       print("done");       setState(() {         isLoading = false;       });     }).catchError((e) => print(e));   },   child: new Container(     padding: const EdgeInsets.symmetric(       vertical: 20.0,       horizontal: 20.0,     ),     child: new Row(       mainAxisAlignment: MainAxisAlignment.center,       children: <Widget>[         new Expanded(child: Text(  "FORGOT PASSWORD",  textAlign: TextAlign.center,  style: TextStyle(      color: Colors.white,      fontWeight: FontWeight.bold),),         ),       ],     ),   ), ),          ),        ],      ),    ),  ],)));      }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375478.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号