FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.74k stars 1.76k forks source link

architecture same issues #112

Open BelongsH opened 3 years ago

BelongsH commented 3 years ago

Thank you for your valuable advice on the architecture。

I'm looking at your code, there are still many things I can't understand. Need to ask you。

    return BaseWidget<HomeViewModel>(
      viewModel: HomeViewModel(),
      onModelReady: (model) => model.initialise(),
      child: ScreenTypeLayout(
        mobile: OrientationLayout(
          //ioc view
          portrait: (context) => HomeMobilePortrait(),
          landscape: (context) => HomeMobileLandscape(),
        ),
        tablet: HomeViewTablet(),
      ),
    );

BaseWidget need provider ViewModel type . why not create instance according to this ViewModel type ? like java invoke.

abstract class BaseModelWidget<T> extends Widget {
  @protected
  Widget build(BuildContext context, T model);

  @override
  DataProviderElement<T> createElement() => DataProviderElement<T>(this);
}

//
class DataProviderElement<T> extends ComponentElement {
  DataProviderElement(BaseModelWidget widget) : super(widget);

  @override
  BaseModelWidget get widget => super.widget;

  @override
  Widget build() => widget.build(this, Provider.of<T>(this));

  @override
  void update(BaseModelWidget newWidget) {
    super.update(newWidget);
    assert(widget == newWidget);
    rebuild();
  }
}

BaseModelWidget Does it really have a meaning, more often, I think it just comes from provider .

Sometimes, I get confused by its name, whether this is a widget or a viewmodel or even a model .

Please forgive me, this bad English