base.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:provide/provide.dart';
  4. import 'package:rxdart/rxdart.dart';
  5. /// normal click event
  6. abstract class Presenter {
  7. /// 处理点击事件
  8. ///
  9. /// 可根据 [action] 进行区分 ,[action] 应是不可变的量
  10. void onClick(String action);
  11. }
  12. /// ListView Item Click
  13. abstract class ItemPresenter<T> {
  14. /// 处理列表点击事件
  15. ///
  16. /// 可根据 [action] 进行区分 ,[action] 应是不可变的量
  17. void onItemClick(String action, T item);
  18. }
  19. /// BaseProvide
  20. class BaseProvide with ChangeNotifier {
  21. CompositeSubscription compositeSubscription = CompositeSubscription();
  22. /// add [StreamSubscription] to [compositeSubscription]
  23. ///
  24. /// 在 [dispose]的时候能进行取消
  25. addSubscription(StreamSubscription subscription){
  26. compositeSubscription.add(subscription);
  27. }
  28. @override
  29. void dispose() {
  30. super.dispose();
  31. compositeSubscription.dispose();
  32. }
  33. }
  34. /// page的基类 [PageProvideNode]
  35. ///
  36. /// 隐藏了 [ProviderNode] 的调用
  37. abstract class PageProvideNode extends StatelessWidget {
  38. /// The values made available to the [child].
  39. final Providers mProviders = Providers();
  40. Widget buildContent(BuildContext context);
  41. @override
  42. Widget build(BuildContext context) {
  43. return ProviderNode(
  44. providers: mProviders,
  45. child: buildContent(context),
  46. );
  47. }
  48. }