edit_text_page.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. int mType = 0;
  8. EditTextPage({this.title,this.mType});
  9. @override
  10. State<StatefulWidget> createState() {
  11. return EditTextState();
  12. }
  13. }
  14. class EditTextState extends State<EditTextPage> {
  15. TextEditingController _valueController = TextEditingController();
  16. ///保存数据
  17. void saveEditText(){
  18. String value = _valueController.text.toString();
  19. if(value.length==0){
  20. toasts("请输入内容");
  21. return;
  22. }else{
  23. Navigator.of(context).pop(value);
  24. }
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. appBar: MyAppBar(
  30. centerTitle: widget.title,
  31. actions: <Widget>[
  32. FlatButton(
  33. child: Text("完成"),
  34. textColor: Colours.dark_text,
  35. highlightColor: Colors.transparent,
  36. onPressed: () {
  37. saveEditText();
  38. },
  39. )
  40. ],
  41. ),
  42. body: ListView(
  43. children: <Widget>[
  44. _bodyWidget(),
  45. ],
  46. ),
  47. );
  48. }
  49. Widget _bodyWidget(){
  50. switch(widget.mType){
  51. case 0:
  52. return singleLineEditText();
  53. break;
  54. case 1:
  55. return moreLineEditText();
  56. break;
  57. }
  58. }
  59. Widget singleLineEditText(){
  60. return Container(
  61. height: 50,
  62. padding: EdgeInsets.only(left: 15,right: 15),
  63. child: TextField(
  64. controller: _valueController,
  65. decoration: InputDecoration(
  66. border: InputBorder.none,
  67. hintText: "请填写",
  68. hintStyle: TextStyle(color: Colours.text),
  69. ),
  70. maxLines: 1,
  71. ),
  72. );
  73. }
  74. Widget moreLineEditText(){
  75. return Container(
  76. height: 100,
  77. padding: EdgeInsets.only(left: 15,right: 15),
  78. decoration: BoxDecoration(
  79. border: Border(
  80. bottom: BorderSide(
  81. color: Colours.text,
  82. style: BorderStyle.solid,
  83. width: 0.5)
  84. )
  85. ),
  86. child: TextField(
  87. maxLength: 30,
  88. controller: _valueController,
  89. decoration: InputDecoration(
  90. border: InputBorder.none,
  91. hintText: "请填写",
  92. hintStyle: TextStyle(color: Colours.text),
  93. ),
  94. maxLines: 2,
  95. ),
  96. );
  97. }
  98. }