import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; ///每个页面顶层使用这个状态 abstract class BasePageState extends State { // Widget build(BuildContext context) { // return MultiProvider(providers: [ // ChangeNotifierProvider.value(value: BaseChangeNotifier()), // ], child: child); // } BaseChangeNotifier baseChangeNotifier; @override Widget build(BuildContext context) { if(baseChangeNotifier==null){ baseChangeNotifier = BaseChangeNotifier(); } return MultiProvider(providers: [ ChangeNotifierProvider.value(value: baseChangeNotifier), ], child: buildX(context)); } Widget buildX(BuildContext context); ///刷新,所继承的子类调用此方法可刷新子组件 void refreshPage() { baseChangeNotifier.refresh(); } } ///每个需要刷新的小组件使用这个状态 abstract class BaseWidgetState extends State { RefreshListener refreshListener = RefreshListener(); @override void didChangeDependencies() { refreshListener.listen(context, (value) { print("刷新子控件"); refreshWidget(value); }); super.didChangeDependencies(); } @override void dispose() { //refreshListener?.close(); super.dispose(); } void refreshWidget(String value); }