YSHome.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_tzh/home/view/YSHomeListItemView.dart';
  4. import 'package:flutter_tzh/tool/YSNetWork.dart';
  5. import 'package:flutter_tzh/tool/YSRefrehLoad.dart';
  6. import 'package:flutter_tzh/tool/YSTools.dart';
  7. import '../mine/YSMineGatherPlan.dart';
  8. class YSHome extends StatefulWidget {
  9. const YSHome({Key? key}) : super(key: key);
  10. @override
  11. YSHomeState createState() => YSHomeState();
  12. }
  13. class YSHomeState extends State<YSHome> {
  14. List _dataArray = [];
  15. final List _headArray = [
  16. {'status':'全部','number':0,'key':'total'},
  17. {'status':'待采样','number':0,'key':'sam'},
  18. {'status':'进行中','number':0,'key':'ing'},
  19. {'status':'已完成','number':0,'key':'end'}
  20. ];
  21. @override
  22. void initState() {
  23. Future.delayed(const Duration(seconds: 0)).then((value) {
  24. _getHomeSampStatistics();
  25. });
  26. super.initState();
  27. }
  28. _getHomeSampStatistics() async{
  29. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: '/samp/statistics', parameter: {}, successSetter: (dict){
  30. Map data = dict['data']??{};
  31. for (Map element in _headArray) {
  32. element['number'] = data[element['key']]??0;
  33. }
  34. setState(() {});
  35. });
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. backgroundColor: Colors.transparent,
  41. body: SingleChildScrollView(
  42. child: Stack(
  43. children: [
  44. // Image.asset('images/card-bg.png',height: hsp(200),width: ysWidth(context),),
  45. Container(
  46. height: hsp(200),
  47. decoration: const BoxDecoration(
  48. gradient: LinearGradient(colors: [Color(0xFF3E434E),Color(0xFF8A93A0)])
  49. ),
  50. alignment: Alignment.center,
  51. child: SizedBox(
  52. width: ysWidth(context)*0.6,
  53. height: hsp(120),
  54. child: GridView.builder(
  55. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  56. crossAxisCount: 2,
  57. childAspectRatio: 2,
  58. ),
  59. itemBuilder: (context,index){
  60. Map item = _headArray[index];
  61. return Container(
  62. alignment: Alignment.center,
  63. child: Column(
  64. mainAxisSize: MainAxisSize.min,
  65. // crossAxisAlignment: CrossAxisAlignment.start,
  66. children: [
  67. Text(item['status']??'',style: TextStyle(fontSize: zsp(13),color: const Color(0xFFACB5C5)),),
  68. Text('${item['number']}',style: TextStyle(fontSize: zsp(22),color: Colors.white),maxLines: 1,)
  69. ],
  70. ),
  71. );
  72. },
  73. itemCount: _headArray.length,
  74. padding: const EdgeInsets.all(0),
  75. physics: const NeverScrollableScrollPhysics(),
  76. ),
  77. ),
  78. ),
  79. Container(
  80. margin: EdgeInsets.only(top: hsp(170)),
  81. height: ysHeight(context)-114-hsp(170),
  82. decoration: const BoxDecoration(
  83. color: Color(0xFF23262B),
  84. borderRadius: BorderRadius.all(Radius.circular(24))
  85. ),
  86. child: Column(
  87. children: [
  88. Container(
  89. height: hsp(40),
  90. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  91. child: Row(
  92. children: [
  93. SizedBox(
  94. width: ysWidth(context)*0.7-hsp(30),
  95. child: Text('采样计划',style: TextStyle(fontSize: zsp(14),color: Colors.white),),
  96. ),
  97. GestureDetector(
  98. onTap: (){
  99. Navigator.of(context).push(
  100. CupertinoPageRoute(builder: (context){
  101. return const YSMineGatherPlan();
  102. })
  103. );
  104. },
  105. behavior: HitTestBehavior.opaque,
  106. child: Container(
  107. alignment: Alignment.centerRight,
  108. width: ysWidth(context)*0.3,
  109. child: Text('查看更多',style: TextStyle(fontSize: zsp(11),color: const Color(0xFFACB5C5)),),
  110. ),
  111. )
  112. ],
  113. ),
  114. ),
  115. SizedBox(
  116. height: ysHeight(context)-114-hsp(210),
  117. child: YSRefreshLoad(
  118. postData: (value) {
  119. _dataArray = value;
  120. setState(() {});
  121. },
  122. url: '/samp/index',
  123. request: const {},
  124. child: SingleChildScrollView(
  125. child: ListView.separated(
  126. itemBuilder: (context, index) {
  127. Map item = _dataArray[index];
  128. return YSHomeListItemView(item: item);
  129. },
  130. separatorBuilder: (context,index){
  131. return Container(height: hsp(16),);
  132. },
  133. itemCount: _dataArray.length,
  134. padding: const EdgeInsets.all(0),
  135. shrinkWrap: true,
  136. physics: const NeverScrollableScrollPhysics(),
  137. ),
  138. ),
  139. ),
  140. )
  141. ],
  142. ),
  143. )
  144. ],
  145. )
  146. ),
  147. );
  148. }
  149. }