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>(
|
child: ValueListenableBuilder<bool>(
|
||||||
valueListenable: galleryViewModel.isViewingFavouriteListenable,
|
valueListenable: galleryViewModel.isViewingFavouriteListenable,
|
||||||
builder: (context, final isViewingFavourites, _) => !isViewingFavourites
|
builder: (context, final isViewingFavourites, _) => !isViewingFavourites
|
||||||
? Wrap(
|
? CustomWrap(children: [
|
||||||
runSpacing: 24,
|
for (final imageModel in galleryViewModel.imageModels)
|
||||||
spacing: 8,
|
_StarrableImage(
|
||||||
alignment: WrapAlignment.center,
|
key: ValueKey(imageModel.imageIndex),
|
||||||
runAlignment: WrapAlignment.center,
|
imageModel: imageModel,
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
galleryViewModel: galleryViewModel,
|
||||||
children: [
|
),
|
||||||
for (final imageModel in galleryViewModel.imageModels)
|
])
|
||||||
_StarrableImage(
|
: CustomWrap(
|
||||||
key: ValueKey(imageModel.imageIndex),
|
|
||||||
imageModel: imageModel,
|
|
||||||
galleryViewModel: galleryViewModel,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: Wrap(
|
|
||||||
runSpacing: 24,
|
|
||||||
spacing: 8,
|
|
||||||
alignment: WrapAlignment.center,
|
|
||||||
runAlignment: WrapAlignment.center,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
for (final favouriteImageModel in galleryViewModel.favouriteImageModels)
|
for (final favouriteImageModel in galleryViewModel.favouriteImageModels)
|
||||||
_StarrableImage(
|
_StarrableImage(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mc_gallery/features/core/data/constants/const_media.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_colors.dart';
|
||||||
import '/features/core/data/constants/const_durations.dart';
|
import '/features/core/data/constants/const_durations.dart';
|
||||||
|
@ -81,21 +82,23 @@ class GalleryView extends StatelessWidget {
|
||||||
valueListenable: model.isSearchingListenable,
|
valueListenable: model.isSearchingListenable,
|
||||||
builder: (context, final isSearching, _) => AnimatedSwitcher(
|
builder: (context, final isSearching, _) => AnimatedSwitcher(
|
||||||
duration: ConstDurations.oneAndHalfDefaultAnimationDuration,
|
duration: ConstDurations.oneAndHalfDefaultAnimationDuration,
|
||||||
child: Column(
|
child: !isSearching
|
||||||
children: [
|
? Column(
|
||||||
ValueListenableBuilder<bool>(
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
valueListenable: model.isViewingFavouriteListenable,
|
children: [
|
||||||
builder: (context, final isViewingFavourites, child) =>
|
ValueListenableBuilder<bool>(
|
||||||
Switch(
|
valueListenable: model.isViewingFavouriteListenable,
|
||||||
value: isViewingFavourites,
|
builder:
|
||||||
onChanged: model.onFavouriteViewChange,
|
(context, final isViewingFavourites, child) =>
|
||||||
),
|
Switch(
|
||||||
),
|
value: isViewingFavourites,
|
||||||
!isSearching
|
onChanged: model.onFavouriteViewChange,
|
||||||
? _DownloadedGalleryView(galleryViewModel: model)
|
),
|
||||||
: _SearchGalleryView(galleryViewModel: model),
|
),
|
||||||
],
|
_DownloadedGalleryView(galleryViewModel: model),
|
||||||
),
|
],
|
||||||
|
)
|
||||||
|
: _SearchGalleryView(galleryViewModel: model),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,7 @@ class _SearchGalleryView extends StatelessWidget {
|
||||||
builder: (context, final searchOption, child) {
|
builder: (context, final searchOption, child) {
|
||||||
switch (searchOption) {
|
switch (searchOption) {
|
||||||
case SearchOption.local:
|
case SearchOption.local:
|
||||||
return Wrap(
|
return CustomWrap(
|
||||||
runSpacing: 24,
|
|
||||||
spacing: 8,
|
|
||||||
alignment: WrapAlignment.center,
|
|
||||||
runAlignment: WrapAlignment.center,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
for (final resultsImageModel in resultsImageModels)
|
for (final resultsImageModel in resultsImageModels)
|
||||||
CachedNetworkImage(
|
CachedNetworkImage(
|
||||||
|
@ -48,12 +43,7 @@ class _SearchGalleryView extends StatelessWidget {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
case SearchOption.web:
|
case SearchOption.web:
|
||||||
return Wrap(
|
return CustomWrap(
|
||||||
runSpacing: 24,
|
|
||||||
spacing: 8,
|
|
||||||
alignment: WrapAlignment.center,
|
|
||||||
runAlignment: WrapAlignment.center,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
for (final imageResult in resultsImageModels)
|
for (final imageResult in resultsImageModels)
|
||||||
Image.network(
|
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