edit_text_page.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/resources.dart';
  3. import 'package:liftmanager/utils/toast.dart';
  4. import 'package:liftmanager/widgets/app_bar.dart';
  5. class EditTextPage extends StatefulWidget {
  6. String title = "";
  7. String value = "";
  8. int mType = 0;
  9. Function saveName;
  10. EditTextPage({this.title, this.value, this.mType, this.saveName});
  11. @override
  12. State<StatefulWidget> createState() {
  13. return EditTextState();
  14. }
  15. }
  16. class EditTextState extends State<EditTextPage> {
  17. TextEditingController _valueController = TextEditingController();
  18. ///保存数据
  19. void saveEditText() {
  20. String value = _valueController.text.toString();
  21. if (value.length == 0) {
  22. toasts("请输入内容");
  23. return;
  24. } else {
  25. widget.saveName(value);
  26. Navigator.of(context).pop(value);
  27. }
  28. }
  29. @override
  30. void initState() {
  31. super.initState();
  32. _valueController = TextEditingController.fromValue(
  33. TextEditingValue(text: widget.value),
  34. );
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return Scaffold(
  39. appBar: MyAppBar(
  40. centerTitle: widget.title,
  41. // isBack: false,
  42. // actions: <Widget>[
  43. // FlatButton(
  44. // child: Text("完成"),
  45. // textColor: Colours.text,
  46. // highlightColor: Colors.transparent,
  47. // onPressed: () {
  48. // saveEditText();
  49. // },
  50. // )
  51. // ],
  52. ),
  53. body: Column(
  54. children: [
  55. _bodyWidget(),
  56. Expanded(child: Container()),
  57. Container(
  58. margin: EdgeInsets.fromLTRB(25, 15, 25, 15),
  59. height: 44,
  60. width: double.infinity,
  61. decoration: BoxDecoration(
  62. color: Colours.blue_app_main,
  63. borderRadius: BorderRadius.circular(22),
  64. ),
  65. child: FlatButton(
  66. // padding: EdgeInsets.all(15.0),
  67. child: Text("保存"),
  68. textColor: Colors.white,
  69. onPressed: () {
  70. saveEditText();
  71. },
  72. ),
  73. ),
  74. ],
  75. )
  76. // ListView(
  77. // children: <Widget>[
  78. // _bodyWidget(),
  79. // Container(
  80. // margin: EdgeInsets.fromLTRB(25, 15, 25, 15),
  81. // height: 44,
  82. // width: double.infinity,
  83. // decoration: BoxDecoration(
  84. // color: Colours.blue_app_main,
  85. // borderRadius: BorderRadius.circular(22),
  86. // ),
  87. // child: FlatButton(
  88. // // padding: EdgeInsets.all(15.0),
  89. // child: Text("保存"),
  90. // textColor: Colors.white,
  91. // onPressed: () {},
  92. // ),
  93. // ),
  94. // ],
  95. // ),
  96. );
  97. }
  98. Widget _bodyWidget() {
  99. switch (widget.mType) {
  100. case 0:
  101. return singleLineEditText();
  102. break;
  103. case 1:
  104. return moreLineEditText();
  105. break;
  106. }
  107. }
  108. Widget singleLineEditText() {
  109. return Container(
  110. height: 50,
  111. padding: EdgeInsets.only(left: 15, right: 15),
  112. child: TextField(
  113. controller: _valueController,
  114. decoration: InputDecoration(
  115. border: InputBorder.none,
  116. hintText: "请填写",
  117. hintStyle: TextStyle(color: Colours.text),
  118. ),
  119. maxLines: 1,
  120. ),
  121. );
  122. }
  123. Widget moreLineEditText() {
  124. return Container(
  125. height: 100,
  126. padding: EdgeInsets.only(left: 15, right: 15),
  127. decoration: BoxDecoration(
  128. border: Border(
  129. bottom: BorderSide(
  130. color: Colours.text, style: BorderStyle.solid, width: 0.5))),
  131. child: TextField(
  132. maxLength: 30,
  133. controller: _valueController,
  134. decoration: InputDecoration(
  135. border: InputBorder.none,
  136. hintText: "请填写",
  137. hintStyle: TextStyle(color: Colours.text),
  138. ),
  139. maxLines: 2,
  140. ),
  141. );
  142. }
  143. }