我有一个文章页面,其中包含2个部分
这里是订阅按钮的肘部
class SubscriptionCubit extends Cubit<SubscriptionState> {
final ArticleDataSource _articleDataSource;
SubscriptionCubit(this._articleDataSource, bool subscribed)
: super(SubscriptionStatus(subscribed));
void toggle(String publisherId) async {
emit(SubscriptionLoading());
bool isSubscribed = await _articleDataSource.followPublisher(publisherId);
emit(SubscriptionStatus(isSubscribed));
}
}
我的文章页面
class ArticlePage extends StatelessWidget {
final String timezone = DateTime.now().timeZoneName;
final Duration timezoneOffset = DateTime.now().timeZoneOffset;
final String id;
ArticlePage({Key key, @required this.id}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
child: BlocProvider<ArticleBloc>(
create: (context) => ArticleBloc(
articleDataSource:
RepositoryProvider.of<ArticleDataSource>(context),
articleId: id)
..add(Fetch(id: this.id)),
child: BlocBuilder<ArticleBloc, ArticleState>(
builder: (context, state) {
if (state is ArticleLoaded) {
return drawArticle(context, state);
} else {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.white,
),
);
}
},
),
),
),
);
}
}
我面临的问题是以下情况:
subscribed
)问题在于此屏幕上显示的按钮仍然是旧的unsubsribed
而不是subscribed
。
使用GIF更新
按下后退按钮后,如何更新“旧”订阅按钮?