我有国家班

class ListScreenState extends State<ListScreen>...

我想使用AutomaticKeepAliveClientMixin(以防止包含这些屏幕的TabBar被丢弃)和TickerProviderStateMixin,因为我有需要它的动画控制器.但是当我把这两个Mixin都放在这个类中时,会出现一个错误:

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)

我真的找不到一个很好的解释如何在一个类中使用mixin.感谢您的帮助.

以下是完整的代码:

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特别抱怨添加了TickerProviderStateMixin.如果我删除AutomaticKeepAliveClientMixin,它就不会再抱怨了.

推荐答案

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

}

Flutter相关问答推荐

使用Flutter 提供程序包加载状态应用程序时,在自定义按钮中显示CircularProgressIndicator

如何在表格日历标题下方添加文本?

Flutter API请求BadState响应

查询满足AND条件的文档的FiRestore

在选项卡栏视图中搜索和筛选不起作用

从Firestore流式传输单个文档还是整个集合更好?

在 flutter 的列中使用 Expanded 时出现渲染 Flex 错误

Flutter - Stripe:类型List 不是类型Map 的子类型? method_channel_stripe.dart 中的错误:263

2023 年如何使用 youtube_explode_dart 包下载 URL?

如果其他Provider 的帐户已存在,如何阻止用户登录?

小部件堆栈未显示顶层

Flutter Dart 功能弹出错误的小部件?

Flutterfire Configure - 未处理的异常和没有 firebase 初始化

当我将主题更改为深色然后返回浅色模式时,Getx 会Flutter 更改主题,它不会加载我的自定义主题

如何在 GridView.builder 中设置 textform 字段并在 flutter 中将 12 个 textformfield 作为单个字符串获取?

我正在try 使用 Firebase 在 Flutter 中使用 Google 注销,但它不起作用

将 onSaved(value) 从自定义 TextFormField 小部件传递给另一个?

无法列出 com.facebook.android:facebook-login -Facebook 登录问题的版本

在 Flutter Bloc 中具有称为 status 的属性的一种状态或不同的状态,哪个更可取?

如何做到这一点,当我们在 textified 中输入 ab 然后将 applebanana 显示为一个单词?飘飘然