123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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<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 {
- 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,
- actions: <Widget>[
- FlatButton(
- child: Text("完成"),
- textColor: Colours.dark_text,
- highlightColor: Colors.transparent,
- onPressed: () {
- saveEditText();
- },
- )
- ],
- ),
- body: ListView(
- children: <Widget>[
- _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,
- ),
- );
- }
- }
|