基础组件库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

207 rader
6.3 KiB

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