23

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.

1
  • 2
    Please show the code that produces this error. Oct 16, 2018 at 7:11

2 Answers 2

47
class ListScreenState extends State<ListScreen> with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  // TODO: implement wantKeepAlive
  @override
  bool get wantKeepAlive => null;

}
9
  • This works, only if I remove TickerProviderStateMixin Oct 16, 2018 at 7:48
  • What do you mean with "works" or "does not work"? I added this code to my app and it didn't complain. Oct 16, 2018 at 7:49
  • Please also add the code of the ListScreen class declaration. Oct 16, 2018 at 7:49
  • It gives me an 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) Oct 16, 2018 at 7:53
  • 1
    Can you try with beta v0.9.4? Oct 16, 2018 at 7:57
18

For anyone coming here using SingleTickerProviderStateMixin, simply remove the Single from the name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.