YSFind.dart 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import 'package:card_swiper/card_swiper.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_wallet/base/YSBase.dart';
  5. import 'package:flutter_wallet/find/YSLoadUrl.dart';
  6. import 'package:flutter_wallet/find/view/YSBannerView.dart';
  7. import 'package:flutter_wallet/generated/l10n.dart';
  8. import 'package:flutter_wallet/tools/YSColors.dart';
  9. import 'package:flutter_wallet/tools/YSNetWork.dart';
  10. import 'package:flutter_wallet/tools/YSRefrehLoad.dart';
  11. import 'package:provider/provider.dart';
  12. import 'package:skeletons/skeletons.dart';
  13. import '../tools/YSTools.dart';
  14. class YSFind extends StatefulWidget {
  15. const YSFind({Key? key}) : super(key: key);
  16. @override
  17. YSFindState createState() => YSFindState();
  18. }
  19. class YSFindState extends State<YSFind> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
  20. List _titles = [];
  21. TabController? _tabController;
  22. _getTitleData() async{
  23. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'dapptypes', parameter: {}, successSetter: (dict){
  24. _titles = dict['data']['list']??[];
  25. _tabController = TabController(
  26. vsync: this,
  27. length: _titles.length,
  28. );
  29. setState(() {});
  30. });
  31. }
  32. @override
  33. void initState() {
  34. networkDelay((){
  35. _getTitleData();
  36. });
  37. super.initState();
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. super.build(context);
  42. return YSBase(
  43. // backgroundColor: YSColors.containColor(context),
  44. isTab: true,
  45. ysTitle: S.current.FAXIAN,
  46. ysChild: SingleChildScrollView(
  47. padding: EdgeInsets.only(top: hsp(10),left: hsp(15),right: hsp(15)),
  48. child: Skeleton(
  49. isLoading: _tabController==null,
  50. skeleton: Column(
  51. children: [
  52. SkeletonAvatar(
  53. style: SkeletonAvatarStyle(
  54. width: double.infinity,
  55. height: hsp(40)
  56. ),
  57. ),
  58. Padding(
  59. padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15)),
  60. child: SkeletonAvatar(
  61. style: SkeletonAvatarStyle(
  62. width: double.infinity,
  63. height: ysWidth(context)/3
  64. ),
  65. ),
  66. ),
  67. SkeletonAvatar(
  68. style: SkeletonAvatarStyle(
  69. width: double.infinity,
  70. height: hsp(50)
  71. ),
  72. ),
  73. Padding(
  74. padding: EdgeInsets.only(top: hsp(15)),
  75. child: Row(
  76. children: [
  77. SkeletonAvatar(
  78. style: SkeletonAvatarStyle(
  79. width: hsp(50),
  80. height: hsp(50),
  81. borderRadius: const BorderRadius.all(Radius.circular(50))
  82. ),
  83. ),
  84. Padding(
  85. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  86. child: SkeletonAvatar(
  87. style: SkeletonAvatarStyle(
  88. width: hsp(50),
  89. height: hsp(50),
  90. borderRadius: const BorderRadius.all(Radius.circular(50))
  91. ),
  92. ),
  93. ),
  94. SkeletonAvatar(
  95. style: SkeletonAvatarStyle(
  96. width: hsp(50),
  97. height: hsp(50),
  98. borderRadius: const BorderRadius.all(Radius.circular(50))
  99. ),
  100. ),
  101. ],
  102. ),
  103. )
  104. ],
  105. ),
  106. child: Column(
  107. children: [
  108. SizedBox(
  109. height: hsp(40),
  110. child: Row(
  111. children: [
  112. Container(
  113. width: ysWidth(context)-hsp(60),
  114. padding: EdgeInsets.only(left: hsp(10),right: hsp(10)),
  115. decoration: BoxDecoration(
  116. color: YSColors.contain2Color(context),
  117. borderRadius: const BorderRadius.all(Radius.circular(5))
  118. ),
  119. child: CupertinoTextField(
  120. placeholder: S.current.QINGSHURUWANGZHI,
  121. style: YSColors.contentStyle(context),
  122. decoration: const BoxDecoration(),
  123. prefix: Image.asset(YSColors.imageStyle(context, '搜索 (6)'),height: hsp(15),width: hsp(15),),
  124. textInputAction: TextInputAction.done,
  125. onSubmitted: (value){
  126. FocusScope.of(context).unfocus();
  127. if(value.isNotEmpty){
  128. intoPage(context,value);
  129. }
  130. },
  131. ),
  132. ),
  133. Padding(
  134. padding: EdgeInsets.only(left: hsp(10)),
  135. child: GestureDetector(
  136. onTap: () async{
  137. String result = await YSCodeImage.scanCode();
  138. if(result.isNotEmpty&&mounted){
  139. intoPage(context,result);
  140. }
  141. },
  142. child: Image.asset(YSColors.imageStyle(context, '扫码 (3)'),height: hsp(20),width: hsp(20),),
  143. )
  144. ),
  145. ],
  146. ),
  147. ),
  148. Container(
  149. margin: EdgeInsets.only(top: hsp(15),bottom: hsp(15)),
  150. height: ysWidth(context)/3,
  151. child: Consumer(
  152. builder: (BuildContext context, CurrentLocale value, Widget? child) {
  153. return YSBannerView(key: Key(value.locale.languageCode),);
  154. },
  155. ),
  156. ),
  157. SizedBox(
  158. height: ysHeight(context)-ysTOP(context)-hsp(200)-ysWidth(context)/3,
  159. width: ysWidth(context),
  160. child: _tabController!=null?DefaultTabController(
  161. length: _titles.length,
  162. child: Column(
  163. children: [
  164. SizedBox(
  165. height: hsp(50),
  166. child: TabBar(
  167. controller: _tabController,
  168. indicatorColor: YSColors.selectedColor(context),
  169. isScrollable: true,
  170. indicatorWeight: hsp(1),
  171. tabs: _titles.map((f) {
  172. return Tab(
  173. child: Text(f['name'],style: YSColors.contentStyle(context),),
  174. );
  175. }).toList(),
  176. ),
  177. ),
  178. SizedBox(
  179. height: ysHeight(context)-ysTOP(context)-hsp(250)-ysWidth(context)/3,
  180. child: TabBarView(
  181. controller: _tabController,
  182. children: _titles.map((f) {
  183. return YSFindDataView(item: f,);
  184. }).toList(),
  185. ),
  186. )
  187. ],
  188. ),
  189. ):Container(),
  190. )
  191. ],
  192. ),
  193. ),
  194. ),
  195. );
  196. }
  197. @override
  198. bool get wantKeepAlive => true;
  199. }
  200. intoPage(BuildContext context,String url) {
  201. Navigator.of(context).push(
  202. CupertinoPageRoute(builder: (context){
  203. return YSLoadUrl(url: url);
  204. })
  205. );
  206. }
  207. class YSFindDataView extends StatefulWidget {
  208. final Map item;
  209. const YSFindDataView({Key? key, required this.item}) : super(key: key);
  210. @override
  211. YSFindDataViewState createState() => YSFindDataViewState();
  212. }
  213. class YSFindDataViewState extends State<YSFindDataView> {
  214. List _dataArray = [];
  215. @override
  216. Widget build(BuildContext context) {
  217. double width = (ysWidth(context)-hsp(90))/5;
  218. return YSRefreshLoad(
  219. url: 'dapps',
  220. request: {'type':widget.item['type']},
  221. postData: (value) {
  222. _dataArray = value;
  223. setState(() {});
  224. },
  225. child: SingleChildScrollView(
  226. padding: EdgeInsets.only(top: hsp(15)),
  227. child: GridView.builder(
  228. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  229. crossAxisCount: 5,
  230. crossAxisSpacing: hsp(15),
  231. mainAxisSpacing: hsp(15),
  232. childAspectRatio: width/(width+hsp(20))
  233. ),
  234. itemBuilder: (context,index){
  235. Map item = _dataArray[index];
  236. return GestureDetector(
  237. onTap: (){
  238. intoPage(context,item['url']);
  239. },
  240. child: Column(
  241. children: [
  242. Container(
  243. height: width-hsp(10),
  244. width: width-hsp(10),
  245. margin: EdgeInsets.only(bottom: hsp(5)),
  246. decoration: BoxDecoration(
  247. borderRadius: const BorderRadius.all(Radius.circular(50)),
  248. image: DecorationImage(image: NetworkImage(item['icon']))
  249. ),
  250. ),
  251. Container(
  252. width: width,
  253. height: hsp(20),
  254. alignment: Alignment.center,
  255. child: SingleChildScrollView(
  256. scrollDirection: Axis.horizontal,
  257. child: Text(item['name']??'',style: YSColors.subStyle(context),maxLines: 1,),
  258. )
  259. )
  260. ],
  261. ),
  262. );
  263. },
  264. itemCount: _dataArray.length,
  265. padding: const EdgeInsets.all(0),
  266. shrinkWrap: true,
  267. physics: const NeverScrollableScrollPhysics(),
  268. ),
  269. ),
  270. );
  271. }
  272. }