我想使用水平页面滚动来渲染卡片,并且能够在每次可见时看到前一个和后一个卡片的边框。Flutter的PageView小部件几乎可以产生我想要的结果,但它没有按照我想要的方式对齐页面。这是我的代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PageView Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'PageView Alignment'),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: PageView.builder(
itemCount: 5,
itemBuilder: (context, i) => Container(
color: Colors.blue,
margin: const EdgeInsets.only(right: 10),
child: Center(child: Text("Page $i")),
),
controller: PageController(viewportFraction: .7),
),
);
}
}
我希望PageView对齐到屏幕左侧,或者至少对于第一页,即去掉Page 0
左侧的空白空间。我是否遗漏了任何PageView参数?或者是否存在其他组件可以实现我想要的结果?