Skip to content

Commit afc9d9c

Browse files
committed
Right to Left support (bdlukaa#184)
2 parents 8e46a5e + 9b4fed9 commit afc9d9c

20 files changed

Lines changed: 205 additions & 95 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Date format: DD/MM/YYYY
1212
- Improved fidelity of the suggestions overlay
1313
- When a suggestion is picked, the overlay is automatically closed and the text box is unfocused
1414
- Clear button now only shows when the text box is focused
15+
- Add directionality support ([#184](https://github.com/bdlukaa/fluent_ui/pull/184))
1516

1617
## [3.9.0] - Fidelity - [10/02/2022]
1718

example/lib/main.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:fluent_ui/fluent_ui.dart';
44
import 'package:flutter/foundation.dart';
55
import 'package:flutter_acrylic/flutter_acrylic.dart' as flutter_acrylic;
66
import 'package:provider/provider.dart';
7+
import 'package:system_theme/system_theme.dart';
78
import 'package:url_launcher/link.dart';
89
import 'package:url_strategy/url_strategy.dart';
910

@@ -31,6 +32,8 @@ bool get isDesktop {
3132
void main() async {
3233
WidgetsFlutterBinding.ensureInitialized();
3334

35+
SystemTheme.accentInstance;
36+
3437
setPathUrlStrategy();
3538

3639
if (isDesktop) {
@@ -82,6 +85,12 @@ class MyApp extends StatelessWidget {
8285
glowFactor: is10footScreen() ? 2.0 : 0.0,
8386
),
8487
),
88+
builder: (context, child) {
89+
return Directionality(
90+
textDirection: appTheme.textDirection,
91+
child: child!,
92+
);
93+
},
8594
);
8695
},
8796
);
@@ -118,7 +127,7 @@ class _MyHomePageState extends State<MyHomePage> {
118127
if (kIsWeb) return const Text(appTitle);
119128
return MoveWindow(
120129
child: const Align(
121-
alignment: Alignment.centerLeft,
130+
alignment: AlignmentDirectional.centerStart,
122131
child: Text(appTitle),
123132
),
124133
);

example/lib/screens/forms.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _FormsState extends State<Forms> {
6565
},
6666
textInputAction: TextInputAction.next,
6767
prefix: const Padding(
68-
padding: EdgeInsets.only(left: 8.0),
68+
padding: EdgeInsetsDirectional.only(start: 8.0),
6969
child: Icon(FluentIcons.edit_mail),
7070
),
7171
),

example/lib/screens/inputs.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ class _InputsPageState extends State<InputsPage> {
163163
color: disabled
164164
? FluentTheme.of(context).accentColor.darker
165165
: FluentTheme.of(context).accentColor,
166-
borderRadius: const BorderRadius.horizontal(
167-
left: Radius.circular(4.0),
166+
borderRadius: const BorderRadiusDirectional.horizontal(
167+
start: Radius.circular(4.0),
168168
),
169169
),
170170
height: 24,

example/lib/screens/settings.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ class Settings extends StatelessWidget {
165165
);
166166
}),
167167
],
168+
biggerSpacer,
169+
Text('Text Direction',
170+
style: FluentTheme.of(context).typography.subtitle),
171+
spacer,
172+
...List.generate(TextDirection.values.length, (index) {
173+
final direction = TextDirection.values[index];
174+
return Padding(
175+
padding: const EdgeInsets.only(bottom: 8.0),
176+
child: RadioButton(
177+
checked: appTheme.textDirection == direction,
178+
onChanged: (value) {
179+
if (value) {
180+
appTheme.textDirection = direction;
181+
}
182+
},
183+
content: Text(
184+
'$direction'
185+
.replaceAll('TextDirection.', '')
186+
.replaceAll('rtl', 'Right to left')
187+
.replaceAll('ltr', 'Left to right'),
188+
),
189+
),
190+
);
191+
}).reversed,
168192
],
169193
);
170194
}

example/lib/theme.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class AppTheme extends ChangeNotifier {
4141
_acrylicEffect = acrylicEffect;
4242
notifyListeners();
4343
}
44+
45+
TextDirection _textDirection = TextDirection.ltr;
46+
TextDirection get textDirection => _textDirection;
47+
set textDirection(TextDirection direction) {
48+
_textDirection = direction;
49+
notifyListeners();
50+
}
4451
}
4552

4653
AccentColor get systemAccentColor {

example/pubspec.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ packages:
205205
url: "https://pub.dartlang.org"
206206
source: hosted
207207
version: "0.12.11"
208+
material_color_utilities:
209+
dependency: transitive
210+
description:
211+
name: material_color_utilities
212+
url: "https://pub.dartlang.org"
213+
source: hosted
214+
version: "0.1.3"
208215
meta:
209216
dependency: transitive
210217
description:
@@ -321,7 +328,7 @@ packages:
321328
name: test_api
322329
url: "https://pub.dartlang.org"
323330
source: hosted
324-
version: "0.4.3"
331+
version: "0.4.8"
325332
typed_data:
326333
dependency: transitive
327334
description:

lib/src/controls/form/auto_suggest_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class __AutoSuggestBoxOverlayTileState extends State<_AutoSuggestBoxOverlayTile>
376376
states.isDisabled ? {ButtonStates.none} : states,
377377
),
378378
),
379-
alignment: Alignment.centerLeft,
379+
alignment: AlignmentDirectional.centerStart,
380380
child: EntrancePageTransition(
381381
child: Text(
382382
widget.text,

lib/src/controls/inputs/dropdown_button.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import 'package:flutter/foundation.dart';
33

44
const double _kVerticalOffset = 20.0;
55
const double _kInnerPadding = 5.0;
6+
const Widget _kDefaultDropdownButtonTrailing = Icon(
7+
FluentIcons.chevron_down,
8+
size: 10,
9+
);
610

711
/// A DropDownButton is a button that shows a chevron as a visual indicator that
812
/// it has an attached flyout that contains more options. It has the same
@@ -203,20 +207,16 @@ class _DropDownButtonState extends State<DropDownButton>
203207
final buttonChildren = <Widget>[
204208
if (widget.leading != null)
205209
Padding(
206-
padding: const EdgeInsets.only(right: 8.0),
210+
padding: const EdgeInsetsDirectional.only(end: 8.0),
207211
child: IconTheme.merge(
208212
data: const IconThemeData(size: 20.0),
209213
child: widget.leading!,
210214
),
211215
),
212216
if (widget.title != null) widget.title!,
213217
Padding(
214-
padding: const EdgeInsets.only(left: 8.0),
215-
child: widget.trailing ??
216-
const Icon(
217-
FluentIcons.chevron_down,
218-
size: 10,
219-
),
218+
padding: const EdgeInsetsDirectional.only(end: 8.0),
219+
child: widget.trailing ?? _kDefaultDropdownButtonTrailing,
220220
),
221221
];
222222

@@ -313,12 +313,12 @@ class DropDownButtonItem {
313313
child: Row(mainAxisSize: MainAxisSize.min, children: [
314314
if (leading != null)
315315
Padding(
316-
padding: const EdgeInsets.only(right: 8.0),
316+
padding: const EdgeInsetsDirectional.only(end: 8.0),
317317
child: leading!,
318318
),
319319
if (title != null)
320320
Padding(
321-
padding: const EdgeInsets.only(right: 8.0),
321+
padding: const EdgeInsetsDirectional.only(end: 8.0),
322322
child: title!,
323323
),
324324
if (trailing != null) trailing!,

lib/src/controls/inputs/pill_button_bar.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PillButtonBarItem {
3030
/// See also:
3131
///
3232
/// * [PillButtonBarItem], the item used by pill button bar
33-
/// * [PillButtonTheme], used to style the pill button bar
33+
/// * [PillButtonBarTheme], used to style the pill button bar
3434
class PillButtonBar extends StatelessWidget {
3535
/// Creates a pill button bar.
3636
///
@@ -86,7 +86,7 @@ class PillButtonBar extends StatelessWidget {
8686
}),
8787
),
8888
);
89-
return Align(alignment: Alignment.topLeft, child: bar);
89+
return Align(alignment: AlignmentDirectional.topStart, child: bar);
9090
}
9191
}
9292

0 commit comments

Comments
 (0)