refactoring
This commit is contained in:
parent
68d7f70ded
commit
84ec8304cd
4 changed files with 51 additions and 48 deletions
|
@ -18,27 +18,15 @@ class _DownloadedGalleryView extends StatelessWidget {
|
|||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: galleryViewModel.isViewingFavouriteListenable,
|
||||
builder: (context, final isViewingFavourites, _) => !isViewingFavourites
|
||||
? Wrap(
|
||||
runSpacing: 24,
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
runAlignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
for (final imageModel in galleryViewModel.imageModels)
|
||||
_StarrableImage(
|
||||
key: ValueKey(imageModel.imageIndex),
|
||||
imageModel: imageModel,
|
||||
galleryViewModel: galleryViewModel,
|
||||
),
|
||||
],
|
||||
)
|
||||
: Wrap(
|
||||
runSpacing: 24,
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
runAlignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
? CustomWrap(children: [
|
||||
for (final imageModel in galleryViewModel.imageModels)
|
||||
_StarrableImage(
|
||||
key: ValueKey(imageModel.imageIndex),
|
||||
imageModel: imageModel,
|
||||
galleryViewModel: galleryViewModel,
|
||||
),
|
||||
])
|
||||
: CustomWrap(
|
||||
children: [
|
||||
for (final favouriteImageModel in galleryViewModel.favouriteImageModels)
|
||||
_StarrableImage(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mc_gallery/features/core/data/constants/const_media.dart';
|
||||
import 'package:mc_gallery/features/home/widgets/custom_wrap.dart';
|
||||
|
||||
import '/features/core/data/constants/const_colors.dart';
|
||||
import '/features/core/data/constants/const_durations.dart';
|
||||
|
@ -81,21 +82,23 @@ class GalleryView extends StatelessWidget {
|
|||
valueListenable: model.isSearchingListenable,
|
||||
builder: (context, final isSearching, _) => AnimatedSwitcher(
|
||||
duration: ConstDurations.oneAndHalfDefaultAnimationDuration,
|
||||
child: Column(
|
||||
children: [
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: model.isViewingFavouriteListenable,
|
||||
builder: (context, final isViewingFavourites, child) =>
|
||||
Switch(
|
||||
value: isViewingFavourites,
|
||||
onChanged: model.onFavouriteViewChange,
|
||||
),
|
||||
),
|
||||
!isSearching
|
||||
? _DownloadedGalleryView(galleryViewModel: model)
|
||||
: _SearchGalleryView(galleryViewModel: model),
|
||||
],
|
||||
),
|
||||
child: !isSearching
|
||||
? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: model.isViewingFavouriteListenable,
|
||||
builder:
|
||||
(context, final isViewingFavourites, child) =>
|
||||
Switch(
|
||||
value: isViewingFavourites,
|
||||
onChanged: model.onFavouriteViewChange,
|
||||
),
|
||||
),
|
||||
_DownloadedGalleryView(galleryViewModel: model),
|
||||
],
|
||||
)
|
||||
: _SearchGalleryView(galleryViewModel: model),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,12 +29,7 @@ class _SearchGalleryView extends StatelessWidget {
|
|||
builder: (context, final searchOption, child) {
|
||||
switch (searchOption) {
|
||||
case SearchOption.local:
|
||||
return Wrap(
|
||||
runSpacing: 24,
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
runAlignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
return CustomWrap(
|
||||
children: [
|
||||
for (final resultsImageModel in resultsImageModels)
|
||||
CachedNetworkImage(
|
||||
|
@ -48,12 +43,7 @@ class _SearchGalleryView extends StatelessWidget {
|
|||
],
|
||||
);
|
||||
case SearchOption.web:
|
||||
return Wrap(
|
||||
runSpacing: 24,
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
runAlignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
return CustomWrap(
|
||||
children: [
|
||||
for (final imageResult in resultsImageModels)
|
||||
Image.network(
|
||||
|
|
22
lib/features/home/widgets/custom_wrap.dart
Normal file
22
lib/features/home/widgets/custom_wrap.dart
Normal file
|
@ -0,0 +1,22 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class CustomWrap extends StatelessWidget {
|
||||
const CustomWrap({
|
||||
required this.children,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
runSpacing: 24,
|
||||
spacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
runAlignment: WrapAlignment.center,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue