You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_common_app/lib/views/advertisement/picked_images_container.dart

129 lines
4.0 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
class PickedImagesContainer extends StatelessWidget {
final List<File> pickedImages;
final Function(String filePath)? onCrossPressedPrimary;
final Function(int index, String filePath)? onCrossPressedSecondary;
final int? index;
final bool isReview;
final Function() onAddImagePressed;
const PickedImagesContainer({
Key? key,
required this.pickedImages,
this.onCrossPressedPrimary,
this.onCrossPressedSecondary,
this.index,
required this.onAddImagePressed,
this.isReview = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return GridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 4.0,
mainAxisSpacing: 8.0,
children: List.generate(
isReview ? pickedImages.length : pickedImages.length + 1,
(index) {
if (index == pickedImages.length && !isReview) {
return Container(
decoration: BoxDecoration( color: MyColors.greyButtonColor, border: Border.all(width: 2, color: MyColors.greyAddBorderColor)),
margin: const EdgeInsets.all(8),
alignment: Alignment.center,
child: Container(
height: 24,
width: 24,
decoration: const BoxDecoration(shape: BoxShape.circle, color: MyColors.darkTextColor),
child: const Icon(Icons.add, color: MyColors.white),
),
).onPress(onAddImagePressed);
}
return Center(
child: BuildImageContainer(
file: pickedImages[index],
onCrossPressedPrimary: onCrossPressedPrimary,
onCrossPressedSecondary: onCrossPressedSecondary,
index: index,
isReview: isReview,
),
);
},
),
);
// return Wrap(
// children: pickedImages
// .map((file) => BuildImageContainer(
// file: file,
// onCrossPressedPrimary: onCrossPressedPrimary,
// onCrossPressedSecondary: onCrossPressedSecondary,
// index: index,
// isReview: isReview,
// ))
// .toList(),
// );
}
}
class BuildImageContainer extends StatelessWidget {
final File file;
final Function(String filePath)? onCrossPressedPrimary;
final Function(int index, String filePath)? onCrossPressedSecondary;
final int? index;
final bool isReview;
const BuildImageContainer({
Key? key,
required this.file,
this.onCrossPressedPrimary,
this.onCrossPressedSecondary,
this.index,
this.isReview = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
height: 90,
width: 90,
child: Stack(
children: [
Image.file(
file,
fit: BoxFit.fill,
height: 72,
width: 70,
).paddingAll(8),
!isReview
? Align(
alignment: Alignment.topRight,
child: MyAssets.closeWithOrangeBg.buildSvg(
fit: BoxFit.fill,
height: 30,
width: 30,
),
).onPress(() {
if (onCrossPressedPrimary == null) {
onCrossPressedSecondary!(index!, file.path);
return;
}
onCrossPressedPrimary!(file.path);
})
: const SizedBox()
],
)),
],
);
}
}