Last active
June 27, 2019 18:49
-
-
Save VB10/dac313752dcef3e30e849c352047fe86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseView<T extends BaseModel> extends StatefulWidget { | |
//init builder model context and child delegate | |
final Widget Function(BuildContext context, T model, Widget child) builder; | |
//init onModelReaedy start on model life cycle | |
final Function(T) onModelReady; | |
BaseView({@required this.builder, this.onModelReady}); | |
@override | |
_BaseViewState createState() => _BaseViewState<T>(); | |
} | |
class _BaseViewState<T extends BaseModel> extends State<BaseView<T>> { | |
//getit kütüphanesi ile kullandığımız modelilimiz | |
T model = locator<T>(); | |
@override | |
void initState() { | |
if (widget.onModelReady != null) { | |
//on model metodu var ise gelen modeli parse diyor | |
widget.onModelReady(model); | |
} | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
//değişikleri alt childlara uyarıyor | |
return ChangeNotifierProvider<T>( | |
builder: (context) => model, | |
//tüketici viewmodel ondan türeyen modeller ile sayfaya dokunulup işlem yapılabilir | |
// getit DI sayesınde A-> B modeli data bind edilebilir değiştireiblir | |
child: Consumer<T>( | |
builder: widget.builder, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment