You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
5.8KB

  1. import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart';
  2. import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart';
  3. import 'package:farm_tpf/utils/const_color.dart';
  4. import 'package:farm_tpf/utils/const_string.dart';
  5. import 'package:flutter/material.dart';
  6. class PlotActionScreen extends StatefulWidget {
  7. @override
  8. _PlotActionScreenState createState() => _PlotActionScreenState();
  9. }
  10. class _PlotActionScreenState extends State<PlotActionScreen> {
  11. List<ActionType> actions = new List<ActionType>();
  12. ScrollController _scrollController;
  13. @override
  14. void initState() {
  15. super.initState();
  16. _scrollController = ScrollController()..addListener(() => setState(() {}));
  17. _initActionButtons();
  18. }
  19. _initActionButtons() {
  20. actions.add(ActionType(plot_action_nursery, null, PlotListScreen()));
  21. actions.add(ActionType(plot_action_plant, null, null));
  22. actions.add(ActionType(plot_action_crop_status, null, null));
  23. actions.add(ActionType(plot_action_environment_update, null, null));
  24. actions.add(ActionType(plot_action_dung, null, null));
  25. actions.add(ActionType(plot_action_spraying, null, null));
  26. actions.add(ActionType(plot_action_disease, null, null));
  27. actions.add(ActionType(plot_action_use_water, null, null));
  28. actions.add(ActionType(plot_action_other, null, EditActionOtherScreen()));
  29. actions.add(ActionType(plot_action_harvest, null, null));
  30. actions.add(ActionType(plot_action_finish, null, null));
  31. }
  32. Widget _createActionButtons(ActionType actionType) {
  33. return GestureDetector(
  34. onTap: () {
  35. Navigator.of(context).push(
  36. MaterialPageRoute(builder: (context) => actionType.listScreen));
  37. },
  38. child: Container(
  39. height: 75,
  40. margin: EdgeInsets.all(4.0),
  41. padding: EdgeInsets.all(0.0),
  42. decoration: BoxDecoration(
  43. color: COLOR_CONST.WHITE,
  44. borderRadius: BorderRadius.only(
  45. topLeft: Radius.circular(8.0),
  46. bottomLeft: Radius.circular(8.0),
  47. bottomRight: Radius.circular(8.0),
  48. topRight: Radius.circular(8.0)),
  49. boxShadow: <BoxShadow>[
  50. BoxShadow(
  51. color: COLOR_CONST.GRAY1.withOpacity(0.2),
  52. offset: Offset(1.1, 1.1),
  53. blurRadius: 10.0),
  54. ],
  55. ),
  56. child: Stack(
  57. children: <Widget>[
  58. Positioned(
  59. top: -10,
  60. right: -3,
  61. child: (actionType.addScreen == null)
  62. ? Container()
  63. : IconButton(
  64. icon: Icon(
  65. Icons.add_circle,
  66. size: 40,
  67. color: Colors.green,
  68. ),
  69. onPressed: () {
  70. Navigator.of(context).push(MaterialPageRoute(
  71. builder: (context) => actionType.addScreen));
  72. })),
  73. Positioned.fill(
  74. child: Align(
  75. alignment: Alignment.center,
  76. child: Text(
  77. actionType.actionName,
  78. textAlign: TextAlign.center,
  79. style: TextStyle(
  80. fontWeight: FontWeight.w400,
  81. fontSize: 13,
  82. color: COLOR_CONST.BLACK2,
  83. ),
  84. )),
  85. ),
  86. ],
  87. ),
  88. ));
  89. }
  90. bool _showTitle(BuildContext context) {
  91. var kExpandedHeight = MediaQuery.of(context).size.width * 1.125 + 32;
  92. return _scrollController.hasClients &&
  93. _scrollController.offset > kExpandedHeight - kToolbarHeight;
  94. }
  95. @override
  96. Widget build(BuildContext context) {
  97. return NestedScrollView(
  98. controller: _scrollController,
  99. headerSliverBuilder: (context, innerBoxScrolled) => [
  100. SliverAppBar(
  101. floating: false,
  102. pinned: true,
  103. backgroundColor: Colors.white,
  104. leading: Container(),
  105. title: _showTitle(context) ? Text(plot_detail_title) : null,
  106. //Height flexibleSpace : WidthScreen /2 * 6/16 * 6(row) + 8(space) *4
  107. expandedHeight: MediaQuery.of(context).size.width * 1.125 + 32,
  108. flexibleSpace: _showTitle(context)
  109. ? null
  110. : FlexibleSpaceBar(
  111. centerTitle: true,
  112. title: GridView.count(
  113. shrinkWrap: true,
  114. crossAxisCount: 2,
  115. childAspectRatio: 16 / 6,
  116. children: actions.map(
  117. (item) {
  118. return _createActionButtons(item);
  119. },
  120. ).toList()),
  121. ),
  122. ),
  123. SliverList(
  124. delegate: SliverChildListDelegate([
  125. Container(
  126. alignment: Alignment.center,
  127. child: _showTitle(context)
  128. ? Text("")
  129. : Text(
  130. plot_detail_title,
  131. style: TextStyle(
  132. fontSize: 20, fontWeight: FontWeight.normal),
  133. ))
  134. ]))
  135. ],
  136. body: RefreshIndicator(
  137. backgroundColor: Colors.white,
  138. onRefresh: () async {},
  139. child: ListView.builder(
  140. itemBuilder: (context, index) => ListTile(title: Text("Text $index")),
  141. itemCount: 20,
  142. ),
  143. ),
  144. );
  145. }
  146. }
  147. class ActionType {
  148. Widget addScreen;
  149. Widget listScreen;
  150. String actionName;
  151. ActionType(String actionName, Widget addScreen, Widget listScreen) {
  152. this.actionName = actionName;
  153. this.addScreen = addScreen;
  154. this.listScreen = listScreen;
  155. }
  156. }