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.

164 lines
5.7KB

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