97 lines
3.3 KiB
Dart
97 lines
3.3 KiB
Dart
import 'dart:ui';
|
|
import 'package:birzha/components/imagePlaceHolder.dart';
|
|
import 'package:birzha/core/adaptix/adaptix.dart';
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:birzha/constants.dart';
|
|
import 'package:birzha/screens/photo.dart';
|
|
|
|
class PostImageSlider extends StatefulWidget {
|
|
PostImageSlider({Key? key, this.images = const [], this.fit, this.height}) : super(key: key);
|
|
|
|
final List<String> images;
|
|
final BoxFit? fit;
|
|
final double? height;
|
|
|
|
@override
|
|
__SliderState createState() => __SliderState();
|
|
}
|
|
|
|
class __SliderState extends State<PostImageSlider> {
|
|
List<String> imageUrls = [];
|
|
int page = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
imageUrls = [
|
|
for (var url in widget.images) url,
|
|
]..remove('');
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var bottomBarHeight = 20.adaptedPx();
|
|
var circleHeight = 8.adaptedPx();
|
|
|
|
return Container(
|
|
height: widget.height ?? 320.adaptedPx(),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned.fill(child: Container(color: Theme.of(context).cardColor)),
|
|
PageView(
|
|
children: [
|
|
for (var image in imageUrls)
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context, rootNavigator: true).push(MaterialPageRoute(builder: (_) => PhotoScreen(imageUrls[page])));
|
|
},
|
|
child: CachedNetworkImage(
|
|
imageUrl: image,
|
|
fit: widget.fit ?? BoxFit.contain,
|
|
errorWidget: (context, url, error) => AppImagePlaceholder(),
|
|
placeholder: (_, __) => AppImagePlaceholder(),
|
|
alignment: Alignment.topCenter,
|
|
),
|
|
)
|
|
],
|
|
onPageChanged: (_p) {
|
|
setState(() {
|
|
page = _p;
|
|
});
|
|
},
|
|
),
|
|
Positioned(
|
|
bottom: AppConstants.horizontalPadding(context),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(circleHeight),
|
|
child: Container(
|
|
height: bottomBarHeight,
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withOpacity(0.7),
|
|
),
|
|
padding: EdgeInsets.symmetric(horizontal: circleHeight / 2),
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(sigmaX: 12, sigmaY: 12),
|
|
child: Row(
|
|
children: List.generate(imageUrls.length, (index) {
|
|
bool isSelected = index == page;
|
|
return AnimatedContainer(
|
|
duration: Duration(milliseconds: 300),
|
|
decoration: BoxDecoration(color: Colors.white.withOpacity(isSelected ? 1 : 0.7), shape: BoxShape.circle),
|
|
height: circleHeight * (isSelected ? 1 : 0.7),
|
|
width: circleHeight * (isSelected ? 1 : 0.7),
|
|
margin: EdgeInsets.symmetric(horizontal: circleHeight / 3),
|
|
);
|
|
})),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|