Advertisement
Guest User

Untitled

a guest
May 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.90 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:tabunganku/src/provider/inherited.dart';
  3.  
  4. abstract class BlocBase {
  5.   void dispose();
  6. }
  7.  
  8. class BlocProvider<T extends BlocBase> extends StatefulWidget {
  9.   BlocProvider({
  10.     Key key,
  11.     @required this.child,
  12.     @required this.bloc,
  13.   }) : super(key: key);
  14.  
  15.   final T bloc;
  16.   final Widget child;
  17.  
  18.   @override
  19.   BlockProviderState<T> createState() => BlockProviderState<T>();
  20.  
  21.  
  22.   static BlockProviderState of<T extends BlocBase>(BuildContext context) {
  23.     return (context.inheritFromWidgetOfExactType(Inherit) as Inherit).data;
  24.   }
  25.  
  26. }
  27.  
  28. class BlockProviderState<T> extends State<BlocProvider<BlocBase>> {
  29.  
  30.   @override
  31.   void dispose() {
  32.     widget.bloc.dispose();
  33.     super.dispose();
  34.   }
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     return Inherit(
  39.       data : this,
  40.       child: widget.child,
  41.     );
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement