Skip to content

Commit

Permalink
prevent 0's added at the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
luhluh-17 committed Jun 21, 2020
1 parent 6d8f95b commit 56c15ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
23 changes: 18 additions & 5 deletions lib/providers/calculate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ class Calculate with ChangeNotifier {
}

void _getButtonText(String buttonValue) {
// any operator excluding -
RegExp regExp = RegExp(r'[÷×+]$');
if (expression == '0' && regExp.hasMatch(buttonValue)) {
// prevents multiple 0 input at the beginning
if (expression.startsWith('0') && buttonValue == '0') {
_expression = '0';
return;
}

// dot and any operator excluding -
RegExp regExp1 = RegExp(r'[÷×+]$');
if (expression == '0' && regExp1.hasMatch(buttonValue)) {
// _expression += buttonValue will not work
// _getExpression() returns exp if string not empty
// thus _expression will only return buttonValue
Expand All @@ -150,7 +156,7 @@ class Calculate with ChangeNotifier {
}

// prevents spamming of operators
if (regExp.hasMatch(expression) && regExp.hasMatch(buttonValue)) {
if (regExp1.hasMatch(expression) && regExp1.hasMatch(buttonValue)) {
_deleteLast(calculate: false);
}

Expand Down Expand Up @@ -178,7 +184,14 @@ class Calculate with ChangeNotifier {
return;
}

_expression += buttonValue;
// removes 0 at start
RegExp regExp4 = RegExp(r'\d');
if (expression.startsWith('0') && regExp4.hasMatch(expression)) {
_expression = buttonValue;
} else {
_expression += buttonValue;
}

_result = _getResult();
}

Expand Down
7 changes: 3 additions & 4 deletions lib/providers/color_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const int _brightness = 25;
class ColorProvider with ChangeNotifier {
Color _primary;

var box = Hive.box(boxColor);
final _box = Hive.box(boxColor);

Color get primary => Color(box.get('primary'));
Color get primary => Color(_box.get('primary'));

Color get primaryLight => _primaryLight();

Expand All @@ -20,8 +20,7 @@ class ColorProvider with ChangeNotifier {

updatePrimaryColor(Color color) {
_primary = _primaryColor(color);
final box = Hive.box(boxColor);
box.put('primary', _primary.value);
_box.put('primary', _primary.value);
notifyListeners();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/shadows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BoxDecoration innerShadowCircle(BuildContext context) {
color: _theme.primaryColorLight,
spreadRadius: 20,
blurRadius: 45,
offset: Offset(0, 8), // changes position of shadow
offset: Offset(0, 8),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A new Flutter application.

publish_to: 'none'

version: 1.2.1+7
version: 1.2.2+8

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit 56c15ca

Please sign in to comment.