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

57 lines
1.4 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. import 'package:zhiying_comm/util/base_bloc.dart';
  5. ///每个页面顶层使用这个状态
  6. abstract class BasePageState<T extends StatefulWidget> extends State<T> {
  7. // Widget build(BuildContext context) {
  8. // return MultiProvider(providers: [
  9. // ChangeNotifierProvider.value(value: BaseChangeNotifier()),
  10. // ], child: child);
  11. // }
  12. BaseChangeNotifier baseChangeNotifier;
  13. @override
  14. Widget build(BuildContext context) {
  15. if(baseChangeNotifier==null){
  16. baseChangeNotifier = BaseChangeNotifier();
  17. }
  18. return MultiProvider(providers: [
  19. ChangeNotifierProvider.value(value: baseChangeNotifier),
  20. ], child: buildX(context));
  21. }
  22. Widget buildX(BuildContext context);
  23. ///刷新,所继承的子类调用此方法可刷新子组件
  24. void refreshPage() {
  25. baseChangeNotifier.refresh();
  26. }
  27. }
  28. ///每个需要刷新的小组件使用这个状态
  29. abstract class BaseWidgetState<T extends StatefulWidget> extends State<T> {
  30. RefreshListener refreshListener = RefreshListener();
  31. @override
  32. void didChangeDependencies() {
  33. refreshListener.listen(context, (value) {
  34. print("刷新子控件");
  35. refreshWidget(value);
  36. });
  37. super.didChangeDependencies();
  38. }
  39. @override
  40. void dispose() {
  41. //refreshListener?.close();
  42. super.dispose();
  43. }
  44. void refreshWidget(String value);
  45. }