sách gpt4 ăn đã đi

dart - 如何在 Flutter 的 State 中使用 2 个 mixin?

In lại 作者:IT王子 更新时间:2023-10-29 06:38:26 27 4
mua khóa gpt4 giày nike

我有一个州级

class ListScreenState extends State...

我想使用 AutomaticKeepAliveClientMixin(以防止处理这些屏幕的 TabBar)和 TickerProviderStateMixin,因为我有需要它的动画 Controller 。但是当我将两个 mixin 都放在这个类中时,会出现错误:

error: Type parameters could not be inferred for the mixin 'TickerProviderStateMixin' because the base class implements the mixin's supertype constraint 'State' in multiple conflicting ways (mixin_inference_inconsistent_matching_classes at [myapp] lib/trips/ListScreen.dart:21)

关于如何在一个类中使用 mixins,我真的找不到很好的解释。感谢您的帮助。

Mã hoàn chỉnh như sau:

import 'package:flutter/widgets.dart';    

class ListScreen extends StatefulWidget {

@ghi đè
State createState() {
return ListScreenState();
}
}

class ListScreenState extends State
with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {

AnimationController controller;

@ghi đè
initState không có giá trị() {
super.initState();

controller = AnimationController(
duration: const Duration(milliseconds: 250), vsync: this);

}

@ghi đè
bool get wantKeepAlive => true;
}

Dart 特别提示添加 TickerProviderStateMixin。如果我删除 AutomaticKeepAliveClientMixin,它就不会再提示了。

câu trả lời hay nhất

class ListScreenState extends State with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
// TODO: implement wantKeepAlive
@ghi đè
bool get wantKeepAlive => null;

}

关于dart - 如何在 Flutter 的 State 中使用 2 个 mixin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52829765/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress