200 lines
5.6 KiB
Dart
200 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class PhotoPage extends StatelessWidget {
|
|
const PhotoPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('照片'),
|
|
),
|
|
body: const PhotoGrid(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class PhotoGrid extends StatelessWidget {
|
|
const PhotoGrid({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// TODO: 替换为真实照片数据
|
|
final mockPhotos = List.generate(20, (index) => '照片 ${index + 1}');
|
|
|
|
return GridView.builder(
|
|
padding: const EdgeInsets.all(8),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
crossAxisSpacing: 4,
|
|
mainAxisSpacing: 4,
|
|
childAspectRatio: 1,
|
|
),
|
|
itemCount: mockPhotos.length,
|
|
itemBuilder: (context, index) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => PhotoDetailPage(
|
|
photos: mockPhotos,
|
|
initialIndex: index,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[300],
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.photo, size: 40, color: Colors.grey),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
mockPhotos[index],
|
|
style: const TextStyle(fontSize: 12),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class PhotoDetailPage extends StatefulWidget {
|
|
final List<String> photos;
|
|
final int initialIndex;
|
|
|
|
const PhotoDetailPage({
|
|
super.key,
|
|
required this.photos,
|
|
required this.initialIndex,
|
|
});
|
|
|
|
@override
|
|
State<PhotoDetailPage> createState() => _PhotoDetailPageState();
|
|
}
|
|
|
|
class _PhotoDetailPageState extends State<PhotoDetailPage> {
|
|
late int _currentIndex;
|
|
late PageController _pageController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_currentIndex = widget.initialIndex;
|
|
_pageController = PageController(initialPage: _currentIndex);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.favorite_border),
|
|
onPressed: () {
|
|
// TODO: 实现收藏功能
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('收藏功能待实现')),
|
|
);
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.share),
|
|
onPressed: () {
|
|
// TODO: 实现分享功能
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('分享功能待实现')),
|
|
);
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete),
|
|
onPressed: () {
|
|
// TODO: 实现删除功能
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('删除功能待实现')),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: Stack(
|
|
children: [
|
|
PageView.builder(
|
|
controller: _pageController,
|
|
itemCount: widget.photos.length,
|
|
onPageChanged: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
},
|
|
itemBuilder: (context, index) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height * 0.7,
|
|
color: Colors.grey[800],
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.photo, size: 100, color: Colors.white),
|
|
const SizedBox(height: 20),
|
|
Text(
|
|
widget.photos[index],
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
Positioned(
|
|
bottom: 20,
|
|
left: 0,
|
|
right: 0,
|
|
child: Center(
|
|
child: Text(
|
|
'${_currentIndex + 1} / ${widget.photos.length}',
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |