import 'package:flutter/material.dart'; import 'package:liftmanager/res/resources.dart'; import 'package:liftmanager/utils/toast.dart'; import 'package:liftmanager/widgets/app_bar.dart'; class EditTextPage extends StatefulWidget { String title = ""; String value = ""; int mType = 0; EditTextPage({this.title, this.value, this.mType}); @override State createState() { return EditTextState(); } } class EditTextState extends State { TextEditingController _valueController = TextEditingController(); ///保存数据 void saveEditText() { String value = _valueController.text.toString(); if (value.length == 0) { toasts("请输入内容"); return; } else { Navigator.of(context).pop(value); } } @override void initState() { super.initState(); _valueController = TextEditingController.fromValue( TextEditingValue( text: widget.value ), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar( centerTitle: widget.title, isBack:false, actions: [ FlatButton( child: Text("完成"), textColor: Colours.dark_text, highlightColor: Colors.transparent, onPressed: () { saveEditText(); }, ) ], ), body: ListView( children: [ _bodyWidget(), ], ), ); } Widget _bodyWidget() { switch (widget.mType) { case 0: return singleLineEditText(); break; case 1: return moreLineEditText(); break; } } Widget singleLineEditText() { return Container( height: 50, padding: EdgeInsets.only(left: 15, right: 15), child: TextField( controller: _valueController, decoration: InputDecoration( border: InputBorder.none, hintText: "请填写", hintStyle: TextStyle(color: Colours.text), ), maxLines: 1, ), ); } Widget moreLineEditText() { return Container( height: 100, padding: EdgeInsets.only(left: 15, right: 15), decoration: BoxDecoration( border: Border( bottom: BorderSide( color: Colours.text, style: BorderStyle.solid, width: 0.5))), child: TextField( maxLength: 30, controller: _valueController, decoration: InputDecoration( border: InputBorder.none, hintText: "请填写", hintStyle: TextStyle(color: Colours.text), ), maxLines: 2, ), ); } }