-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
246 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright 2019 The FlutterCandies author. All rights reserved. | ||
// Use of this source code is governed by an Apache license that can be found | ||
// in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:wechat_camera_picker/wechat_camera_picker.dart'; | ||
|
||
import '../extensions/l10n_extensions.dart'; | ||
import 'asset_widget_builder.dart'; | ||
import 'preview_asset_widget.dart'; | ||
|
||
class SelectedAssetsListView extends StatelessWidget { | ||
const SelectedAssetsListView({ | ||
super.key, | ||
required this.assets, | ||
required this.isDisplayingDetail, | ||
required this.onRemoveAsset, | ||
}); | ||
|
||
final List<AssetEntity> assets; | ||
final ValueNotifier<bool> isDisplayingDetail; | ||
final void Function(int index) onRemoveAsset; | ||
|
||
Widget _selectedAssetWidget(BuildContext context, int index) { | ||
final AssetEntity asset = assets.elementAt(index); | ||
return ValueListenableBuilder<bool>( | ||
valueListenable: isDisplayingDetail, | ||
builder: (_, bool value, __) => GestureDetector( | ||
onTap: () async { | ||
if (value) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) => GestureDetector( | ||
onTap: Navigator.of(context).pop, | ||
child: Center(child: PreviewAssetWidget(asset)), | ||
), | ||
); | ||
} | ||
}, | ||
child: RepaintBoundary( | ||
child: ClipRRect( | ||
borderRadius: BorderRadius.circular(8.0), | ||
child: AssetWidgetBuilder( | ||
entity: asset, | ||
isDisplayingDetail: value, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _selectedAssetDeleteButton(BuildContext context, int index) { | ||
return GestureDetector( | ||
onTap: () => onRemoveAsset(index), | ||
child: DecoratedBox( | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(4.0), | ||
color: Theme.of(context).canvasColor.withOpacity(0.5), | ||
), | ||
child: const Icon(Icons.close, size: 18.0), | ||
), | ||
); | ||
} | ||
|
||
Widget selectedAssetsListView(BuildContext context) { | ||
return Expanded( | ||
child: ListView.builder( | ||
shrinkWrap: true, | ||
physics: const BouncingScrollPhysics(), | ||
padding: const EdgeInsets.symmetric(horizontal: 8.0), | ||
scrollDirection: Axis.horizontal, | ||
itemCount: assets.length, | ||
itemBuilder: (BuildContext context, int index) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 8.0, | ||
vertical: 16.0, | ||
), | ||
child: AspectRatio( | ||
aspectRatio: 1.0, | ||
child: Stack( | ||
children: <Widget>[ | ||
Positioned.fill(child: _selectedAssetWidget(context, index)), | ||
ValueListenableBuilder<bool>( | ||
valueListenable: isDisplayingDetail, | ||
builder: (_, bool value, __) => AnimatedPositioned( | ||
duration: kThemeAnimationDuration, | ||
top: value ? 6.0 : -30.0, | ||
right: value ? 6.0 : -30.0, | ||
child: _selectedAssetDeleteButton(context, index), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder<bool>( | ||
valueListenable: isDisplayingDetail, | ||
builder: (_, bool value, __) => AnimatedContainer( | ||
duration: kThemeChangeDuration, | ||
curve: Curves.easeInOut, | ||
height: assets.isNotEmpty | ||
? value | ||
? 120.0 | ||
: 80.0 | ||
: 40.0, | ||
child: Column( | ||
children: <Widget>[ | ||
SizedBox( | ||
height: 20.0, | ||
child: GestureDetector( | ||
onTap: () { | ||
if (assets.isNotEmpty) { | ||
isDisplayingDetail.value = !isDisplayingDetail.value; | ||
} | ||
}, | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
Text(context.l10n.selectedAssetsText), | ||
if (assets.isNotEmpty) | ||
Padding( | ||
padding: const EdgeInsetsDirectional.only(start: 10.0), | ||
child: Icon( | ||
value ? Icons.arrow_downward : Icons.arrow_upward, | ||
size: 18.0, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
selectedAssetsListView(context), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.