gallery_picker/example/lib/examples/bottom_sheet_example.dart

153 lines
5.5 KiB
Dart
Raw Normal View History

2022-12-29 08:45:28 +03:00
import 'package:flutter/material.dart';
2022-12-30 05:18:18 +03:00
// ignore: depend_on_referenced_packages
2022-12-29 08:45:28 +03:00
import 'package:gallery_picker/gallery_picker.dart';
class BottomSheetExample extends StatefulWidget {
const BottomSheetExample({super.key});
@override
State<BottomSheetExample> createState() => _BottomSheetExampleState();
}
class _BottomSheetExampleState extends State<BottomSheetExample> {
List<MediaFile> selectedMedias = [];
int pageIndex = 0;
var controller = PageController(initialPage: 0);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: BottomSheetLayout(
onSelect: (List<MediaFile> selectedMedias) {
this.selectedMedias = selectedMedias;
pageIndex = 0;
if (this.selectedMedias.isNotEmpty) {
2022-12-30 05:18:18 +03:00
Future.delayed(const Duration(milliseconds: 500)).then((value) {
2022-12-29 08:45:28 +03:00
controller.animateToPage(0,
duration: const Duration(milliseconds: 500),
curve: Curves.easeIn);
});
}
setState(() {});
},
config: Config(mode: Mode.dark),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Spacer(),
const Text(
'These are your selected medias',
),
const Divider(),
Expanded(
flex: 5,
child: Stack(children: [
if (selectedMedias.isNotEmpty)
PageView(
controller: controller,
children: [
for (var media in selectedMedias)
Center(
child: MediaProvider(
media: media,
),
)
],
),
if (selectedMedias.isNotEmpty)
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
if (pageIndex < selectedMedias.length - 1) {
pageIndex++;
controller.animateToPage(pageIndex,
duration: const Duration(milliseconds: 500),
curve: Curves.easeIn);
setState(() {});
}
},
child: const Icon(
Icons.chevron_right,
size: 100,
color: Colors.red,
)),
),
if (selectedMedias.isNotEmpty)
Align(
alignment: Alignment.centerLeft,
child: TextButton(
onPressed: () {
if (pageIndex > 0) {
pageIndex--;
controller.animateToPage(pageIndex,
duration: const Duration(milliseconds: 500),
curve: Curves.easeIn);
setState(() {});
}
},
child: const Icon(
Icons.chevron_left,
size: 100,
color: Colors.red,
)),
),
]),
),
SizedBox(
height: 65,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
for (int i = 0; i < selectedMedias.length; i++)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: TextButton(
onPressed: () {
pageIndex = i;
controller.animateToPage(pageIndex,
duration: const Duration(milliseconds: 500),
curve: Curves.easeIn);
setState(() {});
},
child: Container(
width: 65,
height: 50,
decoration: BoxDecoration(
border: Border.all(
width: 2,
color: pageIndex == i
? Colors.red
: Colors.black)),
child: ThumbnailMedia(
media: selectedMedias[i],
)),
),
)
],
),
),
2022-12-30 05:18:18 +03:00
const Spacer(
2022-12-29 08:45:28 +03:00
flex: 1,
),
TextButton(
onPressed: () {
GalleryPicker.openSheet();
},
child: const Icon(
Icons.open_in_new,
size: 40,
),
),
2022-12-30 05:18:18 +03:00
const Spacer(
2022-12-29 08:45:28 +03:00
flex: 1,
),
],
),
),
),
);
}
}