Elementary-team / flutter-elementary

This is a home to a family of Elementary library packages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using TickerProviderStateMixin

pishguy opened this issue · comments

in MVVM model as this library how can i implement TickerProviderStateMixin or SingleTickerProviderStateMixin the same as StatefulWidget? i know i can separate part of code as a simple class but i want to use in main class

Hi. There are some ready-to-use mixins for ticker provider. https://github.com/Elementary-team/flutter-elementary/blob/main/packages/elementary/lib/src/ticker/ticker_providers.dart
They are should be applied to WidgetModel.

@MbIXjkee could you tell me how can i implement createTicker method and implementing AnimationController or TabController with that?

for example this is my simple viewModel class:

LocationScreenWidgetModel defaultLocationScreenWidgetModelFactory(BuildContext context) {
  final model = context.read<LocationScreenModel>();
  return LocationScreenWidgetModel(model,);
}

class LocationScreenWidgetModel extends WidgetModel<LocationScreenWidget, LocationScreenModel> 
implements ILocationScreenWidgetModel, SingleTickerProviderWidgetModelMixin {
  LocationScreenWidgetModel(super.model);

 ///

  @override
  Ticker createTicker(TickerCallback onTick) =>Ticker(onTick);
}

abstract class ILocationScreenWidgetModel implements IWidgetModel {
///
}

thanks

You don't need to implement createTicker, there is packages/elementary/lib/src/ticker/ticker_providers.dart with mixins that are already implemented everything needs to be a tickerProvider. When you need AnimationController, you just create it inside WM (with mixin) and provide this inside as a ticker provider.