Flutter之撸一个漂亮的登录界面的总结

本文介绍了如何在Flutter中实现TextForm和PageView组件,以及InheritedWidget的使用,以数据共享为例。同时强调了系统化学习的重要性,分享了作者关于Android开发的全套学习资料和面试准备指南。
摘要由CSDN通过智能技术生成

例如,输入账号和密码的TextForm的实现

/**

  • 创建登录界面的TextForm
    /
    Widget buildSignInTextForm() {
    return new Container(
    decoration:
    new BoxDecoration(
    borderRadius: BorderRadius.all(Radius.circular(8))
    , color: Colors.white
    ),
    width: 300,
    height: 190,
    /
    *
  • Flutter提供了一个Form widget,它可以对输入框进行分组,
  • 然后进行一些统一操作,如输入内容校验、输入框重置以及输入内容保存。
    */
    child: new Form(
    key: _SignInFormKey,
    //开启自动检验输入内容,最好还是自己手动检验,不然每次修改子孩子的TextFormField的时候,其他TextFormField也会被检验,感觉不是很好
    // autovalidate: true,
    child: new Column(
    mainAxisSize: MainAxisSize.min,
    children: [
    Flexible(
    child: Padding(
    padding: const EdgeInsets.only(
    left: 25, right: 25, top: 20, bottom: 20),
    child: new TextFormField(
    //关联焦点
    focusNode: emailFocusNode,
    onEditingComplete: () {
    if (focusScopeNode == null) {
    focusScopeNode = FocusScope.of(context);
    }
    focusScopeNode.requestFocus(passwordFocusNode);
    },

decoration: new InputDecoration(
icon: new Icon(Icons.email, color: Colors.black,),
hintText: “Email Address”,
border: InputBorder.none
),
style: new TextStyle(fontSize: 16, color: Colors.black),
//验证
validator: (value) {
if (value.isEmpty) {
return “Email can not be empty!”;
}
},
onSaved: (value) {

},
),
),
),
new Container(
height: 1,
width: 250,
color: Colors.grey[400],
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 20),
child: new TextFormField(
focusNode: passwordFocusNode,
decoration: new InputDecoration(
icon: new Icon(Icons.lock, color: Colors.black,),
hintText: “Password”,
border: InputBorder.none,
suffixIcon: new IconButton(icon: new Icon(
Icons.remove_red_eye, color: Colors.black,),
onPressed: showPassWord)
),
//输入密码,需要用*****显示
obscureText: !isShowPassWord,
style: new TextStyle(fontSize: 16, color: Colors.black),
validator: (value) {
if (value == null || value.isEmpty || value.length < 6) {
return “Password’length must longer than 6!”;
}
},
onSaved: (value) {

},
),
),
),

],
),),
);
}

例如,PageView的实现

PageController _pageController;
PageView _pageView;
int _currentPage = 0;

@override
void initState() {
super.initState();
_pageController = new PageController();
_pageView = new PageView(
controller: _pageController,
children: [
new SignInPage(),
new SignUpPage(),
],
onPageChanged: (index) {
setState(() {
_currentPage = index;
});
},
);
}

3. InheritedWidget的使用

例如,我想在任意一个地方的子控件,想获得用户的数据User,就可以利用InheritedWidget来实现。比如我们平时用的Theme.of(context)在任何地方来获取应用的主题,或者用MediaQuery.of(context)来获取应用的屏幕数据,其实本质上都是用了InheritedWidget来实现数据的共享。

具体的用法,后面再写一篇文章来解释吧(最近刚弄懂)

/**

  • 利用InheritedWidget用于子节点向祖先节点获取数据
    当依赖的InheritedWidget rebuild,会触发子控件的didChangeDependencies()接口
    */
    class UserProvider extends InheritedWidget {
    final Widget child;
    final User user;//在子树中共享的数据

UserProvider({this.user, this.child}) : super(child: child);

/**

  • 该回调决定当数据发生变化时,是否通知子树中依赖数据的Widget
    */
    @override
    bool updateShouldNotify(InheritedWidget oldWidget) {
    return true;
    }
    }

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

如何做好面试突击,规划学习方向?

面试题集可以帮助你查漏补缺,有方向有针对性的学习,为之后进大厂做准备。但是如果你仅仅是看一遍,而不去学习和深究。那么这份面试题对你的帮助会很有限。最终还是要靠资深技术水平说话。

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。建议先制定学习计划,根据学习计划把知识点关联起来,形成一个系统化的知识体系。

学习方向很容易规划,但是如果只通过碎片化的学习,对自己的提升是很慢的。

同时我还搜集整理2020年字节跳动,以及腾讯,阿里,华为,小米等公司的面试题,把面试的要求和技术点梳理成一份大而全的“ Android架构师”面试 Xmind(实际上比预期多花了不少精力),包含知识脉络 + 分支细节

image

在搭建这些技术框架的时候,还整理了系统的高级进阶教程,会比自己碎片化学习效果强太多。

image

点击:《Android架构视频+BAT面试专题PDF+学习笔记》即可免费获取~

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

点击:《Android架构视频+BAT面试专题PDF+学习笔记》即可免费获取~

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

  • 22
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值