I have a state class
class ListScreenState extends State<ListScreen>...
And I want to use AutomaticKeepAliveClientMixin (to prevent the TabBar that holds these screens from disposing of) and TickerProviderStateMixin because I have the animation controller that requires it. But when I put both mixins in this class there's an error:
error: Type parameters could not be inferred for the mixin 'TickerProviderStateMixin' because the base class implements the mixin's supertype constraint 'State<T>' in multiple conflicting ways (mixin_inference_inconsistent_matching_classes at [myapp] lib/trips/ListScreen.dart:21)
I couldn't really find a good explanation of how to use mixins in one class. Any help is appreciated.
Here's the full code:
import 'package:flutter/widgets.dart';
class ListScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return ListScreenState();
}
}
class ListScreenState extends State<ListScreen>
with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 250), vsync: this);
}
@override
bool get wantKeepAlive => true;
}
Dart specifically complains about adding TickerProviderStateMixin. If I remove AutomaticKeepAliveClientMixin, then it doesn't complain anymore.
To implement a mixin , create a class that extends Object and declares no constructors. Unless you want your mixin to be usable as a regular class, use the mixin keyword instead of class . In this way, your Car can run , but cannot be ' handleControlled '.
In Flutter, that means a setState() function is being called somewhere. The Dart package and its class, StateSet, will allow access to the State object previously instantiated back on the home screen — the very State object that built the home screen. That's huge!
The class 'SearchDelegate' can't be used as a mixin because it extends a class other than Object. Because of calling the constructor with-param, it would be better to call a new class where you can implement SearchDelegate easily.
Dart inheritance Inheritance refers to a class's capability to derive properties and behaviors from another class. Dart allows one class to inherit from another, generating a new class from an existing one. We use the extend keyword to inherit from another class.
class ListScreenState extends State<ListScreen> with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
// TODO: implement wantKeepAlive
@override
bool get wantKeepAlive => null;
}
For anyone coming here using SingleTickerProviderStateMixin
, simply remove the Single
from the name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With