Skip to content

Commit 7c7864a

Browse files
authored
✨ Support RTL (#122)
* ✨ Support RTL * 🚀 Add localizations definition in the example
1 parent f19e70d commit 7c7864a

9 files changed

+98
-62
lines changed

example/lib/main.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
///
55
import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
7+
import 'package:flutter_localizations/flutter_localizations.dart';
78
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
89

910
import 'constants/extensions.dart';
@@ -41,6 +42,16 @@ class MyApp extends StatelessWidget {
4142
child: w!,
4243
);
4344
},
45+
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
46+
GlobalWidgetsLocalizations.delegate,
47+
GlobalMaterialLocalizations.delegate,
48+
GlobalCupertinoLocalizations.delegate,
49+
],
50+
supportedLocales: const <Locale>[
51+
Locale('zh'), // Chinese
52+
// Locale('iw'), // Hebrew
53+
],
54+
locale: const Locale('zh'),
4455
);
4556
}
4657
}

example/lib/pages/custom_picker_page.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ class _CustomPickerPageState extends State<CustomPickerPage>
140140
child: Stack(
141141
children: <Widget>[
142142
Positioned.fill(child: _selectedAssetWidget(index)),
143-
AnimatedPositioned(
143+
AnimatedPositionedDirectional(
144144
duration: kThemeAnimationDuration,
145145
top: isDisplayingDetail ? 6.0 : -30.0,
146-
right: isDisplayingDetail ? 6.0 : -30.0,
146+
end: isDisplayingDetail ? 6.0 : -30.0,
147147
child: _selectedAssetDeleteButton(index),
148148
),
149149
],
@@ -740,15 +740,15 @@ class FileAssetPickerBuilder
740740
selector: (_, FileAssetPickerProvider p) => p.pathEntityList,
741741
builder: (_, Map<Directory, Uint8List?> pathEntityList, __) {
742742
return ListView.separated(
743-
padding: const EdgeInsets.only(top: 1.0),
743+
padding: const EdgeInsetsDirectional.only(top: 1.0),
744744
itemCount: pathEntityList.length,
745745
itemBuilder: (_, int index) => pathEntityWidget(
746746
context: context,
747747
list: pathEntityList,
748748
index: index,
749749
),
750750
separatorBuilder: (_, __) => Container(
751-
margin: const EdgeInsets.only(left: 60.0),
751+
margin: const EdgeInsetsDirectional.only(start: 60.0),
752752
height: 1.0,
753753
color: theme.canvasColor,
754754
),
@@ -770,7 +770,7 @@ class FileAssetPickerBuilder
770770
child: Container(
771771
height: appBarItemHeight,
772772
constraints: BoxConstraints(maxWidth: Screens.width * 0.5),
773-
padding: const EdgeInsets.only(left: 12.0, right: 6.0),
773+
padding: const EdgeInsetsDirectional.only(start: 12.0, end: 6.0),
774774
decoration: BoxDecoration(
775775
borderRadius: BorderRadius.circular(999),
776776
color: theme.dividerColor,
@@ -791,7 +791,7 @@ class FileAssetPickerBuilder
791791
),
792792
),
793793
Padding(
794-
padding: const EdgeInsets.only(left: 5.0),
794+
padding: const EdgeInsetsDirectional.only(start: 5.0),
795795
child: DecoratedBox(
796796
decoration: BoxDecoration(
797797
shape: BoxShape.circle,
@@ -851,9 +851,12 @@ class FileAssetPickerBuilder
851851
),
852852
Expanded(
853853
child: Padding(
854-
padding: const EdgeInsets.only(left: 15.0, right: 20.0),
854+
padding: const EdgeInsetsDirectional.only(
855+
start: 15.0,
856+
end: 20.0,
857+
),
855858
child: Padding(
856-
padding: const EdgeInsets.only(right: 10.0),
859+
padding: const EdgeInsetsDirectional.only(end: 10.0),
857860
child: Text(
858861
path.path,
859862
style: const TextStyle(fontSize: 18.0),
@@ -1160,7 +1163,7 @@ class FileAssetPickerViewerBuilderDelegate
11601163
right: 0.0,
11611164
height: Screens.bottomSafeHeight + bottomDetailHeight,
11621165
child: Container(
1163-
padding: EdgeInsets.only(bottom: Screens.bottomSafeHeight),
1166+
padding: EdgeInsetsDirectional.only(bottom: Screens.bottomSafeHeight),
11641167
color: themeData.canvasColor.withOpacity(0.85),
11651168
child: Column(
11661169
children: <Widget>[
@@ -1272,7 +1275,10 @@ class FileAssetPickerViewerBuilderDelegate
12721275
right: 0.0,
12731276
height: Screens.topSafeHeight + kToolbarHeight,
12741277
child: Container(
1275-
padding: EdgeInsets.only(top: Screens.topSafeHeight, right: 12.0),
1278+
padding: EdgeInsetsDirectional.only(
1279+
top: Screens.topSafeHeight,
1280+
end: 12.0,
1281+
),
12761282
color: themeData.canvasColor.withOpacity(0.85),
12771283
child: Row(
12781284
children: <Widget>[
@@ -1454,7 +1460,7 @@ class FileAssetPickerViewerBuilderDelegate
14541460

14551461
Widget _appleOSSelectButton(bool isSelected, File asset) {
14561462
return Padding(
1457-
padding: const EdgeInsets.only(right: 10.0),
1463+
padding: const EdgeInsetsDirectional.only(end: 10.0),
14581464
child: GestureDetector(
14591465
behavior: HitTestBehavior.opaque,
14601466
onTap: () {

example/lib/pages/home_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _HomePageState extends State<HomePage> {
5252
}
5353

5454
Widget get header => Container(
55-
margin: const EdgeInsets.only(top: 30.0),
55+
margin: const EdgeInsetsDirectional.only(top: 30.0),
5656
height: 60.0,
5757
child: Row(
5858
mainAxisAlignment: MainAxisAlignment.center,

example/lib/pages/multi_assets_page.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
151151

152152
Widget get methodListView => Expanded(
153153
child: Padding(
154-
padding: const EdgeInsets.only(bottom: 10.0),
154+
padding: const EdgeInsetsDirectional.only(bottom: 10.0),
155155
child: ListView.builder(
156156
padding: const EdgeInsets.symmetric(vertical: 10.0),
157157
itemCount: pickMethods.length,
@@ -182,11 +182,11 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
182182
color: context.themeData.dividerColor,
183183
child: Stack(
184184
children: <Widget>[
185-
AnimatedPositioned(
185+
AnimatedPositionedDirectional(
186186
duration: kThemeAnimationDuration,
187187
top: 0.0,
188-
left: 0.0,
189-
right: 0.0,
188+
start: 0.0,
189+
end: 0.0,
190190
bottom: isDisplayingDetail ? 20.0 : 0.0,
191191
child: Center(
192192
child: Icon(
@@ -195,10 +195,10 @@ class _MultiAssetsPageState extends State<MultiAssetsPage>
195195
),
196196
),
197197
),
198-
AnimatedPositioned(
198+
AnimatedPositionedDirectional(
199199
duration: kThemeAnimationDuration,
200-
left: 0.0,
201-
right: 0.0,
200+
start: 0.0,
201+
end: 0.0,
202202
bottom: isDisplayingDetail ? 0.0 : -20.0,
203203
height: 20.0,
204204
child: Text(

example/lib/pages/single_assets_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class _SingleAssetPageState extends State<SingleAssetPage>
286286
const Text('Selected Assets'),
287287
if (assets.isNotEmpty)
288288
Padding(
289-
padding: const EdgeInsets.only(left: 10.0),
289+
padding: const EdgeInsetsDirectional.only(start: 10.0),
290290
child: Icon(
291291
isDisplayingDetail
292292
? Icons.arrow_downward

example/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13+
flutter_localizations:
14+
sdk: flutter
1315

1416
wechat_assets_picker:
1517
path: ../

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ abstract class AssetPickerBuilderDelegate<A, P> {
155155
Widget gifIndicator(BuildContext context, A asset) {
156156
return PositionedDirectional(
157157
start: 0,
158+
end: 0,
158159
bottom: 0,
159160
child: Container(
160161
padding: const EdgeInsets.all(6.0),
@@ -260,7 +261,7 @@ abstract class AssetPickerBuilderDelegate<A, P> {
260261
builder: (_, List<A> currentAssets, __) => GridView.builder(
261262
controller: gridScrollController,
262263
padding: isAppleOS
263-
? EdgeInsets.only(
264+
? EdgeInsetsDirectional.only(
264265
top: Screens.topSafeHeight + kToolbarHeight,
265266
bottom: bottomActionBarHeight,
266267
)
@@ -319,9 +320,9 @@ abstract class AssetPickerBuilderDelegate<A, P> {
319320
Widget child = Container(
320321
width: Screens.width,
321322
height: bottomActionBarHeight + Screens.bottomSafeHeight,
322-
padding: EdgeInsets.only(
323-
left: 20.0,
324-
right: 20.0,
323+
padding: EdgeInsetsDirectional.only(
324+
start: 20.0,
325+
end: 20.0,
325326
bottom: Screens.bottomSafeHeight,
326327
),
327328
color: theme.primaryColor.withOpacity(isAppleOS ? 0.90 : 1.0),
@@ -550,7 +551,7 @@ class DefaultAssetPickerBuilderDelegate
550551
(isPreviewEnabled || !isSingleAssetMode)
551552
? <Widget>[confirmButton(context)]
552553
: null,
553-
actionsPadding: const EdgeInsets.only(right: 14.0),
554+
actionsPadding: const EdgeInsetsDirectional.only(end: 14.0),
554555
blurRadius: isAppleOS ? appleOSBlurRadius : 0.0,
555556
);
556557
}
@@ -727,7 +728,7 @@ class DefaultAssetPickerBuilderDelegate
727728
),
728729
),
729730
child: Padding(
730-
padding: const EdgeInsets.only(left: 4.0),
731+
padding: const EdgeInsetsDirectional.only(start: 4.0),
731732
child: Text(
732733
Constants.textDelegate.durationIndicatorBuilder(
733734
Duration(seconds: asset.duration),
@@ -754,7 +755,7 @@ class DefaultAssetPickerBuilderDelegate
754755
),
755756
),
756757
child: Padding(
757-
padding: const EdgeInsets.only(left: 4.0, right: 30.0),
758+
padding: const EdgeInsetsDirectional.only(start: 4.0, end: 30.0),
758759
child: Text(
759760
asset.title ?? '',
760761
style: const TextStyle(fontSize: 16.0),
@@ -788,7 +789,7 @@ class DefaultAssetPickerBuilderDelegate
788789
child: Text(
789790
provider.isSelectedNotEmpty && !isSingleAssetMode
790791
? '${Constants.textDelegate.confirm}'
791-
'(${provider.selectedAssets.length}/${provider.maxAssets})'
792+
' (${provider.selectedAssets.length}/${provider.maxAssets})'
792793
: Constants.textDelegate.confirm,
793794
style: TextStyle(
794795
color: provider.isSelectedNotEmpty
@@ -918,7 +919,8 @@ class DefaultAssetPickerBuilderDelegate
918919
RequestType.audio;
919920
return Selector<DefaultAssetPickerProvider, bool>(
920921
selector: (_, DefaultAssetPickerProvider p) => p.isSwitchingPath,
921-
builder: (_, bool isSwitchingPath, Widget? w) => AnimatedPositioned(
922+
builder: (_, bool isSwitchingPath, Widget? w) =>
923+
AnimatedPositionedDirectional(
922924
duration: switchingPathDuration,
923925
curve: switchingPathCurve,
924926
top: isAppleOS
@@ -949,7 +951,7 @@ class DefaultAssetPickerBuilderDelegate
949951
final Map<AssetPathEntity, Uint8List?> list =
950952
c.watch<DefaultAssetPickerProvider>().pathEntityList;
951953
return ListView.separated(
952-
padding: const EdgeInsets.only(top: 1.0),
954+
padding: const EdgeInsetsDirectional.only(top: 1.0),
953955
itemCount: list.length,
954956
itemBuilder: (_, int index) => pathEntityWidget(
955957
context: c,
@@ -958,7 +960,7 @@ class DefaultAssetPickerBuilderDelegate
958960
isAudio: isAudio,
959961
),
960962
separatorBuilder: (BuildContext _, int __) => Container(
961-
margin: const EdgeInsets.only(left: 60.0),
963+
margin: const EdgeInsetsDirectional.only(start: 60.0),
962964
height: 1.0,
963965
color: theme.canvasColor,
964966
),
@@ -976,7 +978,7 @@ class DefaultAssetPickerBuilderDelegate
976978
child: Container(
977979
height: appBarItemHeight,
978980
constraints: BoxConstraints(maxWidth: Screens.width * 0.5),
979-
padding: const EdgeInsets.only(left: 12.0, right: 6.0),
981+
padding: const EdgeInsetsDirectional.only(start: 12.0, end: 6.0),
980982
decoration: BoxDecoration(
981983
borderRadius: BorderRadius.circular(999),
982984
color: theme.dividerColor,
@@ -1002,7 +1004,7 @@ class DefaultAssetPickerBuilderDelegate
10021004
],
10031005
),
10041006
child: Padding(
1005-
padding: const EdgeInsets.only(left: 5.0),
1007+
padding: const EdgeInsetsDirectional.only(start: 5.0),
10061008
child: DecoratedBox(
10071009
decoration: BoxDecoration(
10081010
shape: BoxShape.circle,
@@ -1081,12 +1083,15 @@ class DefaultAssetPickerBuilderDelegate
10811083
),
10821084
Expanded(
10831085
child: Padding(
1084-
padding: const EdgeInsets.only(left: 15.0, right: 20.0),
1086+
padding: const EdgeInsetsDirectional.only(
1087+
start: 15.0,
1088+
end: 20.0,
1089+
),
10851090
child: Row(
10861091
children: <Widget>[
10871092
Flexible(
10881093
child: Padding(
1089-
padding: const EdgeInsets.only(right: 10.0),
1094+
padding: const EdgeInsetsDirectional.only(end: 10.0),
10901095
child: Text(
10911096
pathEntity.name,
10921097
style: const TextStyle(fontSize: 18.0),
@@ -1170,7 +1175,7 @@ class DefaultAssetPickerBuilderDelegate
11701175
child: Text(
11711176
isSelectedNotEmpty
11721177
? '${Constants.textDelegate.preview}'
1173-
'(${provider.selectedAssets.length})'
1178+
' (${provider.selectedAssets.length})'
11741179
: Constants.textDelegate.preview,
11751180
style: TextStyle(
11761181
color: isSelectedNotEmpty
@@ -1255,7 +1260,11 @@ class DefaultAssetPickerBuilderDelegate
12551260
),
12561261
);
12571262
if (isPreviewEnabled) {
1258-
return Positioned(top: 0.0, right: 0.0, child: selectorWidget);
1263+
return PositionedDirectional(
1264+
top: 0.0,
1265+
end: 0.0,
1266+
child: selectorWidget,
1267+
);
12591268
}
12601269
return selectorWidget;
12611270
},
@@ -1337,6 +1346,7 @@ class DefaultAssetPickerBuilderDelegate
13371346
Widget videoIndicator(BuildContext context, AssetEntity asset) {
13381347
return PositionedDirectional(
13391348
start: 0,
1349+
end: 0,
13401350
bottom: 0,
13411351
child: Container(
13421352
width: double.maxFinite,
@@ -1353,16 +1363,19 @@ class DefaultAssetPickerBuilderDelegate
13531363
crossAxisAlignment: CrossAxisAlignment.center,
13541364
children: <Widget>[
13551365
const Icon(Icons.videocam, size: 24.0, color: Colors.white),
1356-
Padding(
1357-
padding: const EdgeInsets.only(left: 4.0),
1358-
child: Text(
1359-
Constants.textDelegate.durationIndicatorBuilder(
1360-
Duration(seconds: asset.duration),
1361-
),
1362-
style: const TextStyle(color: Colors.white, fontSize: 16.0),
1363-
strutStyle: const StrutStyle(
1364-
forceStrutHeight: true,
1365-
height: 1.4,
1366+
Expanded(
1367+
child: Padding(
1368+
padding: const EdgeInsetsDirectional.only(start: 4.0),
1369+
child: Text(
1370+
Constants.textDelegate.durationIndicatorBuilder(
1371+
Duration(seconds: asset.duration),
1372+
),
1373+
style: const TextStyle(color: Colors.white, fontSize: 16.0),
1374+
strutStyle: const StrutStyle(
1375+
forceStrutHeight: true,
1376+
height: 1.4,
1377+
),
1378+
maxLines: 1,
13661379
),
13671380
),
13681381
),

0 commit comments

Comments
 (0)