123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- 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<StatefulWidget> createState() {
- return EditTextState();
- }
- }
- class EditTextState extends State<EditTextPage> {
- 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: <Widget>[
- // 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: <Widget>[
- // _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,
- ),
- );
- }
- }
|