分页显示内容,图片先显示一个,通过controller: PageController(viewportFraction: 0.9),两边可以显示其他图片的边,可以左右划动来查看其他图片。
// Flutter code sample for PageView
//
// Here is an example of [PageView]. It creates a centered [Text] in each of the three pages
// which scroll horizontally.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
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: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
),
);
}
}
/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final PageController controller = PageController(initialPage: 0);
return PageView(
/// [PageView.scrollDirection] defaults to [Axis.horizontal].
/// Use [Axis.vertical] to scroll vertically.
scrollDirection: Axis.horizontal,
controller: PageController(viewportFraction: 0.9),
children: <Widget>[
Container(
color: Colors.blue,
child: Center(
child: Text('First Page'),
),
),
Container(
color: Colors.red,
child: Center(
child: Text('Second Page'),
),
),
Container(
color: Colors.green,
child: Center(
child: Text('Third Page'),
),
),
],
);
}
}