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

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