我需要获取 Flutter 中 Sliver 的 Y 偏移量。之所以要获取Y偏移量,与这个问题有关。
然后我试图从这个答案中得到 Y 偏移量。但我得到了错误type '_RenderSliverPinnedPersistentHeaderForWidgets' is not a subtype of type 'RenderBox' in type cast
我得到一条线索,sliver 不能使用 renderbox,因为它们使用 renderSliver
示例代码:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatelessWidget(),
);
}
}
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget({Key? key}) : super(key: key); …Run Code Online (Sandbox Code Playgroud) 如何检查地图列表是否包含目标值
例如,我有这个模型类:
class Data {
List<Group>? data;
Data({this.data});
}
class Group {
int? id;
List<Weapon>? weaponItems;
String? groupName;
Group({
this.id,
this.weaponItems,
this.groupName,
});
}
class Weapon {
int? id;
String? name;
Weapon({this.id, this.name});
}
Run Code Online (Sandbox Code Playgroud)
从包含嵌套列表的模型:
数据 => 组 => 武器
或者查看下面的变量以查看名为的结构的详细信息mainData
final Data mainData = Data(
data: [
Group(
id: 1,
groupName: 'Assault Riffle',
weaponItems: [
Weapon(id: 1, name: 'Ak47'),
Weapon(id: 2, name: 'M4'),
],
),
Group(
id: 2,
groupName: 'SMG',
weaponItems: [
Weapon(id: 3, name: 'MP5'),
Weapon(id: 4, …Run Code Online (Sandbox Code Playgroud)