我希望一些嵌套的 UI 小部件从左(屏幕外)到右(屏幕上)滑入一个列。该列有一个带有“flex:4”和一个容器的扩展...基本上,我想为这个内部容器设置动画,包括它包含的所有内容。)
有人可以给我看一些死的简单代码,或者代码链接,来做这个动画吗?我的谷歌搜索返回了一些非常大而复杂的例子。我需要一个“Hello World”,而不是 500 行代码!
(我来自 HTML/CSS/Javascript 世界,我知道使用 Jquery 我可以用非常轻量级的代码来实现它。也许我被宠坏了?虽然我喜欢 Flutter!)
回答1
这是带有弹跳物理的水平滚动的示例代码
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: Container(
margin: const EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: ListView(
physics: const BouncingScrollPhysics(),
// This next line does the trick.
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
],
),
),
),
);
}
}