【发布时间】:2022-01-04 07:08:30
【问题描述】:
我正在尝试创建User 类型的列表,如果该列表不为空,请提供列表中的下一个用户。我已经阅读了尽可能多的 Flutter 文档,但我不知所措。
class _SwipePageState extends State<SwipePage> implements PreferredSizeWidget {
getUsers() async {
Box box = await Hive.openBox('usersBox');
swipableUsers = box.values.toList();
}
List swipableUsers = <User>[];
@override
Widget build(BuildContext context) => Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: Container(color: Colors.transparent),
),
body: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
swipableUsers.isEmpty
? const Text('No more users')
: Stack(children: swipableUsers.map(buildUser).toList()),
Expanded(child: Container()),
const BottomButtonsWidget()
],
),
),
);
Widget buildUser(User currentUser) {
int userIndex = swipableUsers.indexOf(currentUser);
bool isUserInFocus = userIndex == swipableUsers.length - 1;
//Do other stuff with currentUser
错误在: Stack(children: swipableUsers.map(buildUser).toList()),,错误是这个问题的标题,The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Widget>'
有没有机会拯救我的小应用程序,还是我纠结的太多以至于没有希望了?提前感谢您的回答:)
【问题讨论】:
-
列出swipableUsers =
[];这是用户数据类型列表,你想在这里放置小部件列表尝试进行更改
标签: list flutter dart box flutter-hive