1
0
Fork 0
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.
 
 
 
 
 
thesis_shop/lib/bloc_provider.dart

51 lines
1.1 KiB

import 'package:flutter/widgets.dart';
import 'package:thesis_shop/bloc/user_bloc.dart';
import 'utils/disposable.dart';
class BlocProvider implements Disposable {
final UserBloc userBloc;
const BlocProvider({required this.userBloc});
@override
Future<void> dispose() async {
await Future.wait<void>([
userBloc.dispose(),
]);
}
}
class AppState extends StatefulWidget {
final Widget child;
final BlocProvider blocProvider;
const AppState({
Key? key,
required this.blocProvider,
required this.child,
}) : super(key: key);
static AppState of(BuildContext context) {
final AppState? state = context.findAncestorWidgetOfExactType();
if (state == null) {
throw Exception("AppState is not an ancestor of this widget");
}
return state;
}
@override
_AppStateState createState() => _AppStateState();
}
class _AppStateState extends State<AppState> {
@override
Widget build(BuildContext context) {
return widget.child;
}
@override
void dispose() {
widget.blocProvider.dispose();
super.dispose();
}
}