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

当我选择一个Textfield时,键盘会移到它上面

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

当我选择一个Textfield时,键盘会移到它上面

组成动画并在TextField
获得焦点时向上移动TextField容器。

有关合成动画的信息,请参阅: Dart Flutter 框架中的合成动画和
链接动画

使用Flutter的FocusNode检测TextField的焦点

编辑:

在这里,我编写了一个示例,该示例完全满足您的要求:

import 'package:flutter/material.dart';void main() => runApp(new MyApp());class MyApp extends StatelessWidget {  @override  Widget build(BuildContext context) {    return new MaterialApp(      debugShowCheckedModeBanner: false,      title: 'Animation Demo',      theme: new ThemeData(        primaryColor: new Color(0xFFFF0000),      ),      home: new FormDemo(),    );  }}class FormDemo extends StatefulWidget {  @override  _FormDemoState createState() => _FormDemoState();}class _FormDemoState extends State<FormDemo> with SingleTickerProviderStateMixin {  AnimationController _controller;  Animation _animation;  FocusNode _focusNode = FocusNode();  @override  void initState() {    super.initState();    _controller = AnimationController(vsync: this, duration: Duration(milliseconds: 300));    _animation = Tween(begin: 300.0, end: 50.0).animate(_controller)    ..addListener(() {      setState(() {});    });    _focusNode.addListener(() {      if (_focusNode.hasFocus) {        _controller.forward();      } else {        _controller.reverse();      }    });  }  @override  void dispose() {    _controller.dispose();    _focusNode.dispose();    super.dispose();  }  @override  Widget build(BuildContext context) {    return Scaffold(      resizeToAvoidBottomPadding: false, // this avoids the overflow error      appBar: AppBar(        title: Text('TextField Animation Demo'),      ),      body: new InkWell( // to dismiss the keyboard when the user tabs out of the TextField        splashColor: Colors.transparent,        onTap: () {          FocusScope.of(context).requestFocus(FocusNode());        },        child: Container(          padding: const EdgeInsets.all(20.0),          child: Column( children: <Widget>[   SizedBox(height: _animation.value),   TextFormField(     decoration: InputDecoration(       labelText: 'I move!',     ),     focusNode: _focusNode,   ) ],          ),        ),      ),    );  }}



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

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

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