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; Function saveName; EditTextPage({this.title, this.value, this.mType, this.saveName}); @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 { widget.saveName(value); 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.text, // highlightColor: Colors.transparent, // onPressed: () { // saveEditText(); // }, // ) // ], ), body: Column( children: [ _bodyWidget(), Expanded(child: Container()), Container( margin: EdgeInsets.fromLTRB(25, 15, 25, 15), height: 44, width: double.infinity, decoration: BoxDecoration( color: Colours.blue_app_main, borderRadius: BorderRadius.circular(22), ), child: FlatButton( // padding: EdgeInsets.all(15.0), child: Text("保存"), textColor: Colors.white, onPressed: () { saveEditText(); }, ), ), ], ) // ListView( // children: [ // _bodyWidget(), // Container( // margin: EdgeInsets.fromLTRB(25, 15, 25, 15), // height: 44, // width: double.infinity, // decoration: BoxDecoration( // color: Colours.blue_app_main, // borderRadius: BorderRadius.circular(22), // ), // child: FlatButton( // // padding: EdgeInsets.all(15.0), // child: Text("保存"), // textColor: Colors.white, // onPressed: () {}, // ), // ), // ], // ), ); } 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, ), ); } }