我想获得容器、小部件、堆栈等的“y”位置。当它显示在屏幕中央时,我想从图像(视频预览图像)更改为视频文件。我能怎么做?
我找到了屏幕高度。我计算了屏幕中心。我找不到集装箱的地方。
我创建了这样一个示例,但该项目并不位于中心。可能我在这里犯了一个算法错误?
class _DedectCenterState extends State<DedectCenter> {
Size _wSize;
int listSize = 4;
List<GlobalKey> _key = [];
ScrollController _sController;
_scrollListener() {
print("scrolling : " + _sController.offset.toString());
setState(() {
getPosition();
});}
@override
void initState() {
for(int i=0; i < listSize; i++) {
_key[i] = new GlobalKey();
}
_sController = ScrollController();
_sController.addListener(_scrollListener);
super.initState();
}
void getPosition(){
double _wCenterTop = (_wSize.height / 2) - 150.0;
double _wCenterBottom = (_wSize.height / 2) + 150.0;
print("center bottom: " + _wCenterBottom.toString());
print("center top: " + …Run Code Online (Sandbox Code Playgroud) 我需要获取 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) flutter ×2