【发布时间】:2019-11-12 15:43:39
【问题描述】:
我想实现双向 Pageview 或全屏 Gridview。
即布局应该是这样的。
| | |
| | |
_____|_______|_______|____
| | |
| | |
.....| i,j | i+1,j |.....
| | |
| | |
_____|_______|_______|_____
| | |
| | |
.....| i,j+1 |i+1,j+1|.....
| | |
| | |
_____|_______|_______|_____
| | |
| | |
| | |
每个i,j 代表一个全屏。因此,设备的视口将只能查看特定的(i,j)
在任何时间点。
从那个位置开始滑动屏幕
- 左,视口转到
i+1, j - 对,视口转到
i-1, j - 向上,视口转到
i, j+1 - 向下,视口转到
i, j-1
我想指定行数、列数。 (不只是 4 个)
到目前为止,这是我的代码。
渲染4个这样的屏幕Video
(SVG)
(我没有处理控制器逻辑)
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
// Hide the status bar
SystemChrome.setEnabledSystemUIOverlays([]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Experiments',
theme: ThemeData.dark(),
home: MyHomePage(title: 'FlutterExps'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
children: [
PageView(
scrollDirection: Axis.vertical,
children: [
ColoredWidget(
color: Colors.cyan,
direction: ">",
),
ColoredWidget(
color: Colors.orange,
direction: ">>",
),
],
),
PageView(
scrollDirection: Axis.vertical,
children: [
ColoredWidget(
color: Colors.green,
direction: "<",
),
ColoredWidget(
color: Colors.yellow,
direction: "<<",
),
],
),
],
),
);
}
}
class ColoredWidget extends StatefulWidget {
final Color color;
final String direction;
const ColoredWidget({
Key key,
@required this.color,
@required this.direction,
}) : super(key: key);
@override
_ColoredWidgetState createState() => _ColoredWidgetState();
}
class _ColoredWidgetState extends State<ColoredWidget>
with AutomaticKeepAliveClientMixin<ColoredWidget> {
@override
Widget build(BuildContext context) {
super.build(context);
return Container(
color: widget.color,
child: Center(
child: Text(
widget.direction,
style: TextStyle(
fontSize: 100,
color: Colors.black,
),
),
));
}
@override
bool get wantKeepAlive => true;
}
但这显然行不通,因为我需要控制所有连接的相邻 PageViews 等。我不明白如何进行。
【问题讨论】:
-
如果无法播放视频
wget "https://res.cloudinary.com/rootworld/video/upload/v1573573771/mp4.mp4",则为 760KB -
我有一个想法,有一个水平滚动的根网页浏览,它包含垂直滚动的
n网页浏览并包含m页面,并且每当任何子网页浏览的页面发生更改时,通知所有其他孩子滚动到该位置。但这似乎效率极低,因为我需要保持所有网页浏览量。