Skip to content

Commit

Permalink
🐛 Various update changes (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Aug 21, 2024
1 parent 1f2ece4 commit 91b2ab6
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 173 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ that can be found in the LICENSE file. -->

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

## Unreleased

*None.*

## 4.3.2

### Fixes

- Fix button displays when tap to record.
- Prevent camera description exceptions when initializing the camera in the lifecycle callback.

### Improvements

- Use more precise overlay styles.
- Switching between different lens with a single camera by default.
- Always delete the preview file when popping from the preview.

## 4.3.1

### Improvements
Expand Down
2 changes: 2 additions & 0 deletions example/lib/l10n/gen/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:intl/intl.dart' as intl;
import 'app_localizations_en.dart';
import 'app_localizations_zh.dart';

// ignore_for_file: type=lint

/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
Expand Down
2 changes: 2 additions & 0 deletions example/lib/l10n/gen/app_localizations_en.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'app_localizations.dart';

// ignore_for_file: type=lint

/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale);
Expand Down
2 changes: 2 additions & 0 deletions example/lib/l10n/gen/app_localizations_zh.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'app_localizations.dart';

// ignore_for_file: type=lint

/// The translations for Chinese (`zh`).
class AppLocalizationsZh extends AppLocalizations {
AppLocalizationsZh([String locale = 'zh']) : super(locale);
Expand Down
44 changes: 21 additions & 23 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../extensions/l10n_extensions.dart';
import '../main.dart';
import '../models/picker_method.dart';
import '../widgets/method_list_view.dart';
import '../widgets/selected_assets_view.dart';
import '../widgets/selected_assets_list_view.dart';

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

class _MyHomePageState extends State<HomePage> {
final ValueNotifier<bool> isDisplayingDetail = ValueNotifier<bool>(true);
final ValueNotifier<AssetEntity?> selectedAsset =
ValueNotifier<AssetEntity?>(null);
List<AssetEntity> assets = <AssetEntity>[];

Future<void> selectAssets(PickMethod model) async {
final AssetEntity? result = await model.method(context);
final result = await model.method(context);
if (result != null) {
selectedAsset.value = result;
assets = [...assets, result];
if (mounted) {
setState(() {});
}
Expand All @@ -38,6 +37,7 @@ class _MyHomePageState extends State<HomePage> {
Widget header(BuildContext context) {
return Container(
margin: const EdgeInsetsDirectional.only(top: 30),
padding: const EdgeInsets.symmetric(horizontal: 20.0),
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -57,11 +57,13 @@ class _MyHomePageState extends State<HomePage> {
children: <Widget>[
Semantics(
sortKey: const OrdinalSortKey(0),
child: Text(
context.l10n.appTitle,
style: Theme.of(context).textTheme.titleLarge,
overflow: TextOverflow.fade,
maxLines: 1,
child: FittedBox(
child: Text(
context.l10n.appTitle,
style: Theme.of(context).textTheme.titleLarge,
overflow: TextOverflow.fade,
maxLines: 1,
),
),
),
Semantics(
Expand Down Expand Up @@ -107,19 +109,15 @@ class _MyHomePageState extends State<HomePage> {
onSelectMethod: selectAssets,
),
),
ValueListenableBuilder<AssetEntity?>(
valueListenable: selectedAsset,
builder: (_, AssetEntity? asset, __) {
if (asset == null) {
return const SizedBox.shrink();
}
return SelectedAssetView(
asset: asset,
isDisplayingDetail: isDisplayingDetail,
onRemoveAsset: () => selectedAsset.value = null,
);
},
),
if (assets.isNotEmpty)
SelectedAssetsListView(
assets: assets,
isDisplayingDetail: isDisplayingDetail,
onRemoveAsset: (int index) {
assets.removeAt(index);
setState(() {});
},
),
],
),
),
Expand Down
147 changes: 147 additions & 0 deletions example/lib/widgets/selected_assets_list_view.dart
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),
],
),
),
);
}
}
Loading

0 comments on commit 91b2ab6

Please sign in to comment.