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

178 lines
5.4 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/others/mine_header_bg_widget.dart';
  9. import 'package:zhiying_base_widget/widgets/wallet/wallet_appbar/wallet_appbar_sk.dart';
  10. import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data_sk.dart';
  11. import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail_sk.dart';
  12. import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income_sk.dart';
  13. import 'package:zhiying_comm/zhiying_comm.dart';
  14. import 'package:zhiying_comm/util/base_bloc.dart';
  15. import 'package:zhiying_comm/util/custom_sliver_persistent_header_delegate.dart';
  16. import 'wallet_page_bloc.dart';
  17. import 'wallet_page_bloc.dart';
  18. ///钱包页面
  19. class WalletPage extends StatefulWidget {
  20. final Map<String, dynamic> data;
  21. const WalletPage({Key key, this.data}) : super(key: key);
  22. @override
  23. _WalletPageState createState() => _WalletPageState();
  24. }
  25. class _WalletPageState extends State<WalletPage> {
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. backgroundColor: Color(0xfff9f9f9),
  30. body: MultiProvider(
  31. providers: [
  32. ChangeNotifierProvider.value(value: MainPageNotifier()),
  33. ChangeNotifierProvider.value(value: MainPageBgNotifier()),
  34. ],
  35. child: BlocProvider<WalletPageBloc>(
  36. bloc: WalletPageBloc(),
  37. child: _WalletPageContainer(data: widget.data),
  38. ),
  39. ),
  40. );
  41. }
  42. }
  43. class _WalletPageContainer extends StatefulWidget {
  44. _WalletPageContainer({Key key, this.data}) : super(key: key);
  45. final Map<String, dynamic> data;
  46. @override
  47. _WalletPageContainerState createState() => _WalletPageContainerState();
  48. }
  49. class _WalletPageContainerState extends State<_WalletPageContainer> {
  50. final ScrollController _controller = ScrollController();
  51. final RefreshController _refreshController =
  52. RefreshController(initialRefresh: false);
  53. WalletPageBloc _pageBloc;
  54. @override
  55. void initState() {
  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. void _onLoading() async {
  63. // await Future.delayed(Duration(milliseconds: 1000));
  64. // if (mounted) setState(() {});
  65. // _refreshController.loadComplete();
  66. }
  67. @override
  68. Widget build(BuildContext context) {
  69. ScreenUtil.init(context, width: 750, height: 1334);
  70. return SmartRefresher(
  71. controller: _refreshController,
  72. enablePullDown: true,
  73. enablePullUp:true,
  74. header: WaterDropHeader(),
  75. onLoading: _onLoading,
  76. child: Container(
  77. width: double.infinity,
  78. child: Stack(
  79. fit: StackFit.passthrough,
  80. children: <Widget>[
  81. StreamBuilder(
  82. stream: _pageBloc.outData,
  83. builder: (context, asyncSnapshot) {
  84. var model = asyncSnapshot.data;
  85. return Stack(
  86. children: <Widget>[
  87. Container(height: 362.h, color: _pageBloc.backgroundColor),
  88. CustomScrollView(
  89. slivers: _createContent(context, model),
  90. )
  91. ],
  92. );
  93. },
  94. )
  95. ],
  96. ),
  97. ),
  98. );
  99. }
  100. List<Widget> _createContent(
  101. BuildContext context, List<Map<String, dynamic>> model) {
  102. List<Widget> list = List();
  103. if (model == null) {
  104. ///骨架图
  105. list.add(SliverToBoxAdapter(
  106. child: WalletAppbarSkeleton(),
  107. ));
  108. list.add(SliverToBoxAdapter(
  109. child: WalletDataSkeleton(),
  110. ));
  111. list.add(SliverToBoxAdapter(
  112. child: WalletIncomeSkeleton(),
  113. ));
  114. list.add(SliverToBoxAdapter(
  115. child: WalletDetailSkeleton(),
  116. ));
  117. } else {
  118. for (var item in model) {
  119. WidgetModel widgetModel =
  120. WidgetModel.fromJson(Map<String, dynamic>.from(item));
  121. if (item.containsKey("mod_name") &&
  122. item['mod_name'] == "my_wallet_appbar") {
  123. list.add(SliverPersistentHeader(
  124. delegate: _SilverAppBarDelegate(
  125. context,
  126. WidgetFactory.create(widgetModel.modName,
  127. isSliver: false, model: item)[0]),
  128. pinned: true,
  129. ));
  130. continue;
  131. }
  132. list.addAll(WidgetFactory.create(widgetModel.modName,
  133. isSliver: true, model: item));
  134. }
  135. }
  136. return list;
  137. }
  138. }
  139. class _SilverAppBarDelegate extends SliverPersistentHeaderDelegate {
  140. _SilverAppBarDelegate(BuildContext context, this.child) {
  141. this.context = context;
  142. }
  143. BuildContext context;
  144. final Widget child;
  145. @override
  146. double get minExtent => MediaQuery.of(context).padding.top + 44;
  147. @override
  148. double get maxExtent => MediaQuery.of(context).padding.top + 44;
  149. @override
  150. Widget build(
  151. BuildContext context, double shrinkOffset, bool overlapsContent) {
  152. return child;
  153. }
  154. @override
  155. bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
  156. return false;
  157. }
  158. }