Skip to content

Commit 8c1c177

Browse files
committed
toggle rtl and ltr view added
1 parent f1c8e8e commit 8c1c177

File tree

6 files changed

+123
-87
lines changed

6 files changed

+123
-87
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ samples, guidance on mobile development, and a full API reference.
2020
[*] Add dark mode
2121
[*] Change status bar color to primary color
2222
[*] Change navigator bar color to primary color
23-
[ ] Toggle rtl and ltr view
23+
[*] Toggle rtl and ltr view
2424
[ ] Customable primary color
2525
[*] Vibration for better UX

lib/components/header.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ class _HeaderState extends State<Header> {
1717
width: double.infinity,
1818
child: Row(
1919
crossAxisAlignment: CrossAxisAlignment.center,
20-
mainAxisAlignment: MainAxisAlignment.end,
20+
mainAxisAlignment:
21+
theme.isLtr() ? MainAxisAlignment.end : MainAxisAlignment.start,
2122
children: [
23+
ButtonIcon(
24+
icon: Icons.swap_horiz,
25+
size: 46,
26+
onPress: () => theme.changePosition(),
27+
brightness: theme.data().brightness,
28+
),
2229
ButtonIcon(
2330
icon: theme.data().primaryColor == Colors.blueGrey[800]
2431
? Icons.wb_sunny

lib/components/pad.dart

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ class Pad extends StatelessWidget {
55
final String entry;
66
final List<History> histories;
77
final Brightness brightness;
8+
final bool ltr;
89

910
Pad({
1011
this.entry,
1112
this.histories,
1213
this.brightness,
14+
this.ltr = true,
1315
});
1416

1517
@override
@@ -59,40 +61,43 @@ class Pad extends StatelessWidget {
5961
double fontSize = 28,
6062
Color color,
6163
}) {
64+
List<Widget> widgets = history.sing != null
65+
? [
66+
Text(
67+
history.sing,
68+
style: TextStyle(
69+
fontSize: 24,
70+
color: color,
71+
),
72+
),
73+
Spacer(),
74+
Text(
75+
history.value,
76+
style: TextStyle(
77+
fontSize: fontSize,
78+
color: color,
79+
),
80+
),
81+
]
82+
: [
83+
Text(
84+
history.value,
85+
style: TextStyle(
86+
fontSize: fontSize,
87+
color: color,
88+
),
89+
),
90+
];
91+
6292
return Container(
6393
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
6494
padding: EdgeInsets.symmetric(
6595
horizontal: 50,
6696
),
6797
child: Row(
68-
mainAxisAlignment: MainAxisAlignment.end,
69-
children: history.sing != null
70-
? [
71-
Text(
72-
history.sing,
73-
style: TextStyle(
74-
fontSize: 24,
75-
color: color,
76-
),
77-
),
78-
Spacer(),
79-
Text(
80-
history.value,
81-
style: TextStyle(
82-
fontSize: fontSize,
83-
color: color,
84-
),
85-
),
86-
]
87-
: [
88-
Text(
89-
history.value,
90-
style: TextStyle(
91-
fontSize: fontSize,
92-
color: color,
93-
),
94-
),
95-
],
98+
mainAxisAlignment:
99+
ltr ? MainAxisAlignment.end : MainAxisAlignment.start,
100+
children: ltr ? widgets : widgets.reversed.toList(),
96101
),
97102
);
98103
}

lib/components/view.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ class View extends StatelessWidget {
44
final Widget child;
55
final double margin;
66
final Color color;
7+
final bool ltr;
78

89
View({
910
this.child,
1011
this.margin = 25,
1112
this.color,
13+
this.ltr = true,
1214
});
1315

1416
@override
@@ -19,10 +21,15 @@ class View extends StatelessWidget {
1921
margin: EdgeInsets.symmetric(vertical: this.margin),
2022
decoration: BoxDecoration(
2123
color: color,
22-
borderRadius: BorderRadius.only(
23-
topLeft: Radius.circular(10),
24-
bottomLeft: Radius.circular(10),
25-
),
24+
borderRadius: ltr
25+
? BorderRadius.only(
26+
topLeft: Radius.circular(10),
27+
bottomLeft: Radius.circular(10),
28+
)
29+
: BorderRadius.only(
30+
topRight: Radius.circular(10),
31+
bottomRight: Radius.circular(10),
32+
),
2633
boxShadow: [
2734
BoxShadow(
2835
color: Colors.black38,

lib/services/theme.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import 'package:flutter/material.dart';
33
import 'package:flutter/services.dart';
44

55
class ThemeProvider with ChangeNotifier {
6+
bool _ltr = true;
67
ThemeData _theme;
78
ThemeData data() => _theme;
9+
bool isLtr() => _ltr;
810

911
ThemeProvider() {
1012
_theme = themes['blue'];
13+
_ltr = true;
1114
_setSystemColor();
1215
notifyListeners();
1316
}
@@ -29,4 +32,9 @@ class ThemeProvider with ChangeNotifier {
2932
statusBarBrightness: Brightness.light,
3033
));
3134
}
35+
36+
void changePosition() {
37+
_ltr = !_ltr;
38+
notifyListeners();
39+
}
3240
}

lib/views/main.dart

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,64 +29,73 @@ class _MainViewState extends State<MainView> {
2929
backgroundColor: theme.data().primaryColor,
3030
body: SafeArea(
3131
child: Row(
32-
children: [
33-
NumbersColumn(
34-
onPressed: (String value) => this.pushToEntry(value),
35-
),
36-
View(
37-
color: theme.data().backgroundColor,
38-
child: Column(
39-
children: [
40-
Header(),
41-
Pad(
42-
entry: entry,
43-
histories: histories,
32+
crossAxisAlignment: CrossAxisAlignment.start,
33+
children: this.children(theme),
34+
),
35+
),
36+
),
37+
);
38+
}
39+
40+
List<Widget> children(ThemeProvider theme) {
41+
List<Widget> widgets = [
42+
NumbersColumn(
43+
onPressed: (String value) => this.pushToEntry(value),
44+
),
45+
View(
46+
ltr: theme.isLtr(),
47+
color: theme.data().backgroundColor,
48+
child: Column(
49+
children: [
50+
Header(),
51+
Pad(
52+
entry: entry,
53+
histories: histories,
54+
brightness: theme.data().brightness,
55+
ltr: theme.isLtr(),
56+
),
57+
Buttons(
58+
count: 4,
59+
children: buttons
60+
.map(
61+
(button) => ButtonText(
62+
button,
63+
onPress: () => this.pushToHistory(button),
4464
brightness: theme.data().brightness,
4565
),
46-
Buttons(
47-
count: 4,
48-
children: buttons
49-
.map(
50-
(button) => ButtonText(
51-
button,
52-
onPress: () => this.pushToHistory(button),
53-
brightness: theme.data().brightness,
54-
),
55-
)
56-
.toList(),
57-
),
58-
Spacer(),
59-
Container(
60-
margin: EdgeInsets.symmetric(
61-
horizontal: 20,
62-
),
63-
child: Row(
64-
children: [
65-
ButtonText(
66-
'C',
67-
onPress: () => this.clear(),
68-
brightness: theme.data().brightness,
69-
),
70-
Spacer(),
71-
ButtonBackspace(
72-
brightness: theme.data().brightness,
73-
onPress: () => this.backspace(),
74-
),
75-
],
76-
),
77-
),
78-
EqualButton(
79-
color: theme.data().primaryColor,
80-
onPressed: () => this.calculate(),
81-
),
82-
],
83-
),
66+
)
67+
.toList(),
68+
),
69+
Spacer(),
70+
Container(
71+
margin: EdgeInsets.symmetric(
72+
horizontal: 20,
8473
),
85-
],
86-
),
74+
child: Row(
75+
children: [
76+
ButtonText(
77+
'C',
78+
onPress: () => this.clear(),
79+
brightness: theme.data().brightness,
80+
),
81+
Spacer(),
82+
ButtonBackspace(
83+
brightness: theme.data().brightness,
84+
onPress: () => this.backspace(),
85+
),
86+
],
87+
),
88+
),
89+
EqualButton(
90+
color: theme.data().primaryColor,
91+
onPressed: () => this.calculate(),
92+
),
93+
],
8794
),
8895
),
89-
);
96+
];
97+
98+
return theme.isLtr() ? widgets : widgets.reversed.toList();
9099
}
91100

92101
void pushToHistory(String sign) {

0 commit comments

Comments
 (0)