Skip to content

Commit 91b2ab6

Browse files
authored
🐛 Various update changes (#271)
1 parent 1f2ece4 commit 91b2ab6

12 files changed

+246
-173
lines changed

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ that can be found in the LICENSE file. -->
66

77
See the [Migration Guide](guides/migration_guide.md) for breaking changes between versions.
88

9+
## Unreleased
10+
11+
*None.*
12+
13+
## 4.3.2
14+
15+
### Fixes
16+
17+
- Fix button displays when tap to record.
18+
- Prevent camera description exceptions when initializing the camera in the lifecycle callback.
19+
20+
### Improvements
21+
22+
- Use more precise overlay styles.
23+
- Switching between different lens with a single camera by default.
24+
- Always delete the preview file when popping from the preview.
25+
926
## 4.3.1
1027

1128
### Improvements

example/lib/l10n/gen/app_localizations.dart

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:intl/intl.dart' as intl;
88
import 'app_localizations_en.dart';
99
import 'app_localizations_zh.dart';
1010

11+
// ignore_for_file: type=lint
12+
1113
/// Callers can lookup localized strings with an instance of AppLocalizations
1214
/// returned by `AppLocalizations.of(context)`.
1315
///

example/lib/l10n/gen/app_localizations_en.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'app_localizations.dart';
22

3+
// ignore_for_file: type=lint
4+
35
/// The translations for English (`en`).
46
class AppLocalizationsEn extends AppLocalizations {
57
AppLocalizationsEn([String locale = 'en']) : super(locale);

example/lib/l10n/gen/app_localizations_zh.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'app_localizations.dart';
22

3+
// ignore_for_file: type=lint
4+
35
/// The translations for Chinese (`zh`).
46
class AppLocalizationsZh extends AppLocalizations {
57
AppLocalizationsZh([String locale = 'zh']) : super(locale);

example/lib/pages/home_page.dart

+21-23
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../extensions/l10n_extensions.dart';
1111
import '../main.dart';
1212
import '../models/picker_method.dart';
1313
import '../widgets/method_list_view.dart';
14-
import '../widgets/selected_assets_view.dart';
14+
import '../widgets/selected_assets_list_view.dart';
1515

1616
class HomePage extends StatefulWidget {
1717
const HomePage({super.key});
@@ -22,13 +22,12 @@ class HomePage extends StatefulWidget {
2222

2323
class _MyHomePageState extends State<HomePage> {
2424
final ValueNotifier<bool> isDisplayingDetail = ValueNotifier<bool>(true);
25-
final ValueNotifier<AssetEntity?> selectedAsset =
26-
ValueNotifier<AssetEntity?>(null);
25+
List<AssetEntity> assets = <AssetEntity>[];
2726

2827
Future<void> selectAssets(PickMethod model) async {
29-
final AssetEntity? result = await model.method(context);
28+
final result = await model.method(context);
3029
if (result != null) {
31-
selectedAsset.value = result;
30+
assets = [...assets, result];
3231
if (mounted) {
3332
setState(() {});
3433
}
@@ -38,6 +37,7 @@ class _MyHomePageState extends State<HomePage> {
3837
Widget header(BuildContext context) {
3938
return Container(
4039
margin: const EdgeInsetsDirectional.only(top: 30),
40+
padding: const EdgeInsets.symmetric(horizontal: 20.0),
4141
height: 60,
4242
child: Row(
4343
mainAxisAlignment: MainAxisAlignment.center,
@@ -57,11 +57,13 @@ class _MyHomePageState extends State<HomePage> {
5757
children: <Widget>[
5858
Semantics(
5959
sortKey: const OrdinalSortKey(0),
60-
child: Text(
61-
context.l10n.appTitle,
62-
style: Theme.of(context).textTheme.titleLarge,
63-
overflow: TextOverflow.fade,
64-
maxLines: 1,
60+
child: FittedBox(
61+
child: Text(
62+
context.l10n.appTitle,
63+
style: Theme.of(context).textTheme.titleLarge,
64+
overflow: TextOverflow.fade,
65+
maxLines: 1,
66+
),
6567
),
6668
),
6769
Semantics(
@@ -107,19 +109,15 @@ class _MyHomePageState extends State<HomePage> {
107109
onSelectMethod: selectAssets,
108110
),
109111
),
110-
ValueListenableBuilder<AssetEntity?>(
111-
valueListenable: selectedAsset,
112-
builder: (_, AssetEntity? asset, __) {
113-
if (asset == null) {
114-
return const SizedBox.shrink();
115-
}
116-
return SelectedAssetView(
117-
asset: asset,
118-
isDisplayingDetail: isDisplayingDetail,
119-
onRemoveAsset: () => selectedAsset.value = null,
120-
);
121-
},
122-
),
112+
if (assets.isNotEmpty)
113+
SelectedAssetsListView(
114+
assets: assets,
115+
isDisplayingDetail: isDisplayingDetail,
116+
onRemoveAsset: (int index) {
117+
assets.removeAt(index);
118+
setState(() {});
119+
},
120+
),
123121
],
124122
),
125123
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright 2019 The FlutterCandies author. All rights reserved.
2+
// Use of this source code is governed by an Apache license that can be found
3+
// in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
7+
8+
import '../extensions/l10n_extensions.dart';
9+
import 'asset_widget_builder.dart';
10+
import 'preview_asset_widget.dart';
11+
12+
class SelectedAssetsListView extends StatelessWidget {
13+
const SelectedAssetsListView({
14+
super.key,
15+
required this.assets,
16+
required this.isDisplayingDetail,
17+
required this.onRemoveAsset,
18+
});
19+
20+
final List<AssetEntity> assets;
21+
final ValueNotifier<bool> isDisplayingDetail;
22+
final void Function(int index) onRemoveAsset;
23+
24+
Widget _selectedAssetWidget(BuildContext context, int index) {
25+
final AssetEntity asset = assets.elementAt(index);
26+
return ValueListenableBuilder<bool>(
27+
valueListenable: isDisplayingDetail,
28+
builder: (_, bool value, __) => GestureDetector(
29+
onTap: () async {
30+
if (value) {
31+
showDialog(
32+
context: context,
33+
builder: (BuildContext context) => GestureDetector(
34+
onTap: Navigator.of(context).pop,
35+
child: Center(child: PreviewAssetWidget(asset)),
36+
),
37+
);
38+
}
39+
},
40+
child: RepaintBoundary(
41+
child: ClipRRect(
42+
borderRadius: BorderRadius.circular(8.0),
43+
child: AssetWidgetBuilder(
44+
entity: asset,
45+
isDisplayingDetail: value,
46+
),
47+
),
48+
),
49+
),
50+
);
51+
}
52+
53+
Widget _selectedAssetDeleteButton(BuildContext context, int index) {
54+
return GestureDetector(
55+
onTap: () => onRemoveAsset(index),
56+
child: DecoratedBox(
57+
decoration: BoxDecoration(
58+
borderRadius: BorderRadius.circular(4.0),
59+
color: Theme.of(context).canvasColor.withOpacity(0.5),
60+
),
61+
child: const Icon(Icons.close, size: 18.0),
62+
),
63+
);
64+
}
65+
66+
Widget selectedAssetsListView(BuildContext context) {
67+
return Expanded(
68+
child: ListView.builder(
69+
shrinkWrap: true,
70+
physics: const BouncingScrollPhysics(),
71+
padding: const EdgeInsets.symmetric(horizontal: 8.0),
72+
scrollDirection: Axis.horizontal,
73+
itemCount: assets.length,
74+
itemBuilder: (BuildContext context, int index) {
75+
return Padding(
76+
padding: const EdgeInsets.symmetric(
77+
horizontal: 8.0,
78+
vertical: 16.0,
79+
),
80+
child: AspectRatio(
81+
aspectRatio: 1.0,
82+
child: Stack(
83+
children: <Widget>[
84+
Positioned.fill(child: _selectedAssetWidget(context, index)),
85+
ValueListenableBuilder<bool>(
86+
valueListenable: isDisplayingDetail,
87+
builder: (_, bool value, __) => AnimatedPositioned(
88+
duration: kThemeAnimationDuration,
89+
top: value ? 6.0 : -30.0,
90+
right: value ? 6.0 : -30.0,
91+
child: _selectedAssetDeleteButton(context, index),
92+
),
93+
),
94+
],
95+
),
96+
),
97+
);
98+
},
99+
),
100+
);
101+
}
102+
103+
@override
104+
Widget build(BuildContext context) {
105+
return ValueListenableBuilder<bool>(
106+
valueListenable: isDisplayingDetail,
107+
builder: (_, bool value, __) => AnimatedContainer(
108+
duration: kThemeChangeDuration,
109+
curve: Curves.easeInOut,
110+
height: assets.isNotEmpty
111+
? value
112+
? 120.0
113+
: 80.0
114+
: 40.0,
115+
child: Column(
116+
children: <Widget>[
117+
SizedBox(
118+
height: 20.0,
119+
child: GestureDetector(
120+
onTap: () {
121+
if (assets.isNotEmpty) {
122+
isDisplayingDetail.value = !isDisplayingDetail.value;
123+
}
124+
},
125+
child: Row(
126+
mainAxisSize: MainAxisSize.min,
127+
children: <Widget>[
128+
Text(context.l10n.selectedAssetsText),
129+
if (assets.isNotEmpty)
130+
Padding(
131+
padding: const EdgeInsetsDirectional.only(start: 10.0),
132+
child: Icon(
133+
value ? Icons.arrow_downward : Icons.arrow_upward,
134+
size: 18.0,
135+
),
136+
),
137+
],
138+
),
139+
),
140+
),
141+
selectedAssetsListView(context),
142+
],
143+
),
144+
),
145+
);
146+
}
147+
}

0 commit comments

Comments
 (0)