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

是否显示文本字段对话框而不被键盘覆盖?

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

是否显示文本字段对话框而不被键盘覆盖?

如果你的使用情况是添加多个

TextFields
内你
Dialog
让你的主
Form
不会显得很拥挤,我觉得这是更好,如果你建立的东西不是更加个性化
alertDialog
,并
SimpleDialog
为它们用于简单的活动(确认,radios..etc)。

否则,为什么要对

Dialog
单个使用a
TextField

当我们添加多个

TextField
s时,我们应该谨慎选择设计,因为其他人将与该视图交互以填充数据,在这种情况下,我更喜欢使用class
fullscreenDialog
属性
PageRoute
。我不确定
SimpleDialog
Flutter 是否适合。

这是一个有关如何使用的快速示例

FullScreenDialog
,希望此帮助,您应该能够按照自己的方式对其进行修改:

import 'package:flutter/material.dart';void main() {  runApp(new MaterialApp(home: new MyApp(),));}class MyApp extends StatefulWidget {  @override  MyAppState createState() => new MyAppState();}class MyAppState extends State<MyApp> {  FullScreenDialog _myDialog = new FullScreenDialog();  @override  Widget build(BuildContext context) {    return new Scaffold(        appBar: new AppBar(          title: new Text("Fill this form"),        ),        body: new Column(          children: <Widget>[ new TextField(controller: new TextEditingController(     text: "Add a single text field"),), new Card(child: new ListTile(   title: new Text("Click to add your top 3 amazing skills"),   subtitle: new Text(       "${_myDialog._skillOne} ${_myDialog._skillTwo} ${_myDialog._skillThree}"),   onTap: () {     Navigator.push(context, new MaterialPageRoute(       builder: (BuildContext context) => _myDialog,       fullscreenDialog: true,     ));   }, ), ),          ],        )    );  }}class FullScreenDialog extends StatefulWidget {  String _skillOne = "You have";  String _skillTwo = "not Added";  String _skillThree = "any skills yet";  @override  FullScreenDialogState createState() => new FullScreenDialogState();}class FullScreenDialogState extends State<FullScreenDialog> {  TextEditingController _skilloneController = new TextEditingController();  TextEditingController _skillTwoController = new TextEditingController();  TextEditingController _skillThreeController = new TextEditingController();  @override  Widget build(BuildContext context) {    return new Scaffold(        appBar: new AppBar(          title: new Text("Add your top 3 skills"),        ),        body: new Padding(child: new ListView(          children: <Widget>[ new TextField(controller: _skillOneController,), new TextField(controller: _skillTwoController,), new TextField(controller: _skillThreeController,), new Row(   children: <Widget>[     new Expanded(child: new RaisedButton(onPressed: () {       widget._skillThree = _skillThreeController.text;       widget._skillTwo = _skillTwoController.text;       widget._skillOne = _skillOneController.text;       Navigator.pop(context);     }, child: new Text("Save"),))   ], )          ],        ), padding: const EdgeInsets.symmetric(horizontal: 20.0),)    );  }}

编辑

经过研究后,看来这是当前Flutter版本中的错误,此问题中也记录了临时修复程序。

import 'package:flutter/material.dart';void main() {  runApp(new MaterialApp(home: new FocusVisibilityDemo()));}class FocusVisibilityDemo extends StatefulWidget {  @override  _FocusVisibilityDemoState createState() => new _FocusVisibilityDemoState();}class _FocusVisibilityDemoState extends State<FocusVisibilityDemo> {  @override  Widget build(BuildContext context) {    return new Scaffold(      appBar: new AppBar(title: new Text('Text Dialog Demo')),      body: new Center(        child: new RaisedButton(          onPressed: _showDialog,          child: new Text("Push Me"),        ),      ),    );  }  _showDialog() async {    await showDialog<String>(      context: context,      child: new _SystemPadding(child: new alertDialog(        contentPadding: const EdgeInsets.all(16.0),        content: new Row(          children: <Widget>[ new Expanded(   child: new TextField(     autofocus: true,     decoration: new InputDecoration(         labelText: 'Full Name', hintText: 'eg. John Smith'),   ), )          ],        ),        actions: <Widget>[          new FlatButton(   child: const Text('CANCEL'),   onPressed: () {     Navigator.pop(context);   }),          new FlatButton(   child: const Text('OPEN'),   onPressed: () {     Navigator.pop(context);   })        ],      ),),    );  }}class _SystemPadding extends StatelessWidget {  final Widget child;  _SystemPadding({Key key, this.child}) : super(key: key);  @override  Widget build(BuildContext context) {    var mediaQuery = MediaQuery.of(context);    return new AnimatedContainer(        padding: mediaQuery.viewInsets,        duration: const Duration(milliseconds: 300),        child: child);  }}


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

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

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