写一个flutter页面布局,全屏显示一张图片,当点击后在图片上左上边显示图片名称,图片底部显示下一张和上一张的图标按钮,图片左边有一个抽屉,点击打开抽屉显示图片列表
时间: 2023-05-22 07:01:05 浏览: 232
好的,以下是一个简单的 Flutter 页面布局代码,可以实现您所描述的功能:
```dart
import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _imageName = 'Image Name';
int _currentIndex = 0;
List<String> _imageList = [
'image1.jpg',
'image2.jpg',
'image3.jpg',
'image4.jpg',
'image5.jpg',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Viewer'),
),
body: GestureDetector(
onTap: () {
setState(() {
_imageName = _imageList[_currentIndex];
});
},
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(_imageList[_currentIndex]),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
margin: EdgeInsets.only(top: 40, left: 20),
child: Text(
_imageName,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
setState(() {
_currentIndex =
(_currentIndex - 1) % _imageList.length;
_imageName = 'Image Name';
});
},
),
IconButton(
icon: Icon(Icons.arrow_forward),
onPressed: () {
setState(() {
_currentIndex =
(_currentIndex + 1) % _imageList.length;
_imageName = 'Image Name';
});
},
),
],
),
],
),
),
),
drawer: Drawer(
child: ListView.builder(
itemCount: _imageList.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(_imageList[index]),
onTap: () {
setState(() {
_currentIndex = index;
_imageName = 'Image Name';
Navigator.pop(context);
});
},
);
},
),
),
);
}
}
```
这个页面布局包括一个全屏的图片,点击图片后会在左上角显示图片名称,底部有上一张和下一张的图标按钮,左边有一个抽屉,点击打开抽屉会显示图片列表。
阅读全文