基础组件库
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.

wallet_page.dart 6.2 KiB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:pull_to_refresh/pull_to_refresh.dart';
  5. import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart';
  6. import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_notifier.dart';
  7. import 'package:zhiying_base_widget/utils/contants.dart';
  8. import 'package:zhiying_base_widget/widgets/base_state/base_state.dart';
  9. import 'package:zhiying_base_widget/widgets/hot_ranking/hot_ranking_list/model/hot_ranking_list_model.dart';
  10. import 'package:zhiying_base_widget/widgets/refresh/refresh_header/refresh_header.dart';
  11. import 'package:zhiying_base_widget/widgets/wallet/wallet_appbar/wallet_appbar_sk.dart';
  12. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
  13. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_sk.dart';
  14. import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income_sk.dart';
  15. import 'package:zhiying_comm/util/base_bloc.dart';
  16. import 'package:zhiying_comm/zhiying_comm.dart';
  17. import 'dart:ui';
  18. import 'package:provider/provider.dart';
  19. import 'wallet_page_bloc.dart';
  20. ///钱包页面
  21. class WalletPage extends StatefulWidget {
  22. final Map<String, dynamic> data;
  23. const WalletPage({Key key, this.data}) : super(key: key);
  24. @override
  25. _WalletPageState createState() => _WalletPageState();
  26. }
  27. class _WalletPageState extends BasePageState<WalletPage> {
  28. @override
  29. Widget buildX(BuildContext context) {
  30. return Scaffold(
  31. backgroundColor: Color(0xfff9f9f9),
  32. body: BlocProvider<WalletPageBloc>(
  33. bloc: WalletPageBloc(),
  34. child: _WalletPageContainer(
  35. data: widget.data,
  36. ),
  37. ),
  38. );
  39. }
  40. }
  41. class _WalletPageContainer extends StatefulWidget {
  42. _WalletPageContainer({Key key, this.data}) : super(key: key);
  43. final Map<String, dynamic> data;
  44. @override
  45. _WalletPageContainerState createState() => _WalletPageContainerState();
  46. }
  47. class _WalletPageContainerState extends State<_WalletPageContainer>
  48. with AutomaticKeepAliveClientMixin {
  49. ScrollController _controller;
  50. RefreshController _refreshController;
  51. WalletPageBloc _pageBloc;
  52. @override
  53. void initState() {
  54. _controller = ScrollController();
  55. _refreshController = RefreshController(initialRefresh: false);
  56. _pageBloc = BlocProvider.of<WalletPageBloc>(context);
  57. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  58. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  59. }
  60. super.initState();
  61. }
  62. @override
  63. void didChangeDependencies() {
  64. var userInfo = Provider.of<UserInfoNotifier>(context);
  65. if (userInfo != null) {
  66. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  67. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  68. Provider.of<BaseChangeNotifier>(context,listen: false).refresh();
  69. }
  70. }
  71. super.didChangeDependencies();
  72. }
  73. @override
  74. void dispose() {
  75. _refreshController?.dispose();
  76. Provider.of<BaseChangeNotifier>(context,listen: false).close();
  77. super.dispose();
  78. }
  79. void _onLoading() async {
  80. // await Future.delayed(Duration(milliseconds: 1000));
  81. // if (mounted) setState(() {});
  82. // _refreshController.loadComplete();
  83. }
  84. void _onRefresh() async {
  85. if (widget.data.containsKey(Constants.SkipIdentifierName)) {
  86. _pageBloc.loadData(widget.data[Constants.SkipIdentifierName]);
  87. }
  88. }
  89. @override
  90. Widget build(BuildContext context) {
  91. ScreenUtil.init(context, width: 750, height: 1334);
  92. double top = MediaQueryData.fromWindow(window).padding.top;
  93. return Container(
  94. width: double.infinity,
  95. child: Stack(
  96. fit: StackFit.passthrough,
  97. children: <Widget>[
  98. StreamBuilder(
  99. stream: _pageBloc.outData,
  100. builder: (context, asyncSnapshot) {
  101. var model = asyncSnapshot.data;
  102. _refreshController.refreshCompleted();
  103. return Stack(
  104. children: <Widget>[
  105. Container(height: 181, color: _pageBloc.backgroundColor),
  106. SmartRefresher(
  107. controller: _refreshController,
  108. enablePullDown: true,
  109. enablePullUp: false,
  110. header: RefreshHeader(
  111. offsetY: top,
  112. ),
  113. onLoading: _onLoading,
  114. onRefresh: _onRefresh,
  115. child: CustomScrollView(
  116. controller: _controller,
  117. slivers: _createContent(context, model),
  118. ),
  119. )
  120. ],
  121. );
  122. },
  123. )
  124. ],
  125. ),
  126. );
  127. }
  128. List<Widget> _createContent(
  129. BuildContext context, List<Map<String, dynamic>> model) {
  130. List<Widget> list = List();
  131. if (model == null) {
  132. ///骨架图
  133. list.add(SliverToBoxAdapter(
  134. child: WalletAppbarSkeleton(),
  135. ));
  136. list.add(SliverToBoxAdapter(
  137. child: WalletDataSkeleton(),
  138. ));
  139. list.add(SliverToBoxAdapter(
  140. child: WalletIncomeSkeleton(),
  141. ));
  142. list.add(SliverToBoxAdapter(
  143. child: WalletDetailSkeleton(),
  144. ));
  145. } else {
  146. for (var item in model) {
  147. WidgetModel widgetModel =
  148. WidgetModel.fromJson(Map<String, dynamic>.from(item));
  149. list.addAll(WidgetFactory.create(widgetModel.modName,
  150. isSliver: true, model: item));
  151. }
  152. }
  153. return list;
  154. }
  155. @override
  156. // TODO: implement wantKeepAlive
  157. bool get wantKeepAlive => true;
  158. }
  159. // class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  160. // _SilverAppBarDelegate(BuildContext context, this.child) {
  161. // this.context = context;
  162. // }
  163. //
  164. // BuildContext context;
  165. // final Widget child;
  166. //
  167. // @override
  168. // double get minExtent => MediaQuery.of(context).padding.top + 44;
  169. //
  170. // @override
  171. // double get maxExtent => MediaQuery.of(context).padding.top + 44;
  172. //
  173. // @override
  174. // Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
  175. // return child;
  176. // }
  177. //
  178. // @override
  179. // bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
  180. // return false;
  181. // }
  182. // }