Skip to content

Commit

Permalink
added history
Browse files Browse the repository at this point in the history
- updated readme and screenshots
  • Loading branch information
danger-ahead committed Jan 22, 2022
1 parent e2f6a1c commit 285d866
Show file tree
Hide file tree
Showing 19 changed files with 211 additions and 80 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ A Soft UI Calculator using Flutter.
<p float="left">

### Light Mode
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/simple-light.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/advanced-light.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/drawer-light.png" height="400" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/simple-light.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/advanced-light.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/history-light.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/drawer-light.png" height="400" />

### Dark Mode
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/simple-dark.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/advanced-dark.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/drawer-dark.png" height="400" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/simple-dark.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/advanced-dark.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/history-dark.png" height="400" />&nbsp;<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/drawer-dark.png" height="400" />
</p>
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added history section
- Added button press UI effects
- Under the hood improvements
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Supports light, dark and system default theme.
Has simple and advnced modes.
Stores previously performed operations.
Comes with Haptic Feedbacks.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

// ignore: depend_on_referenced_packages
import 'package:shared_preferences_web/shared_preferences_web.dart';
// ignore: depend_on_referenced_packages
import 'package:url_launcher_web/url_launcher_web.dart';

// ignore: depend_on_referenced_packages
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
Expand Down
20 changes: 13 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import 'src/calculator_mode_views/calculator_mode_view_rebuilder.dart';
import 'src/theme/app_theme.dart';
import 'src/theme/theme_controller.dart';

final expressionProvider = StateProvider((ref) => '');
final historyProvider = StateProvider((ref) => '');
final hapticFeedbackProvider = StateProvider((ref) => true);
final radianProvider = StateProvider((ref) => true);
final calculatorDisplayDirectionProvider = StateProvider((ref) => true);
final expressionProvider =
StateProvider((ref) => ''); //stores the current expression
final historyProvider =
StateProvider((ref) => ''); //stores the last evaluated expression
final hapticFeedbackProvider =
StateProvider((ref) => true); //stores if haptic feedback is enabled
final radianProvider = StateProvider(
(ref) => true); //stores if expressions are to be evaluated in radians
final calculatorDisplayDirectionProvider = StateProvider((ref) =>
true); //stores if the expression has been calculated and has to be displayed from the beginning

ThemeController themeController = ThemeController();
CalculatorMode calculatorMode = CalculatorMode();
ThemeController themeController = ThemeController(); //controls the app theme
CalculatorMode calculatorMode =
CalculatorMode(); //controls the calculator mode (simple or advanced)

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../../main.dart';
import '../ui/bottom_sheet.dart' as bottom_sheet;
import '../ui/common_drawer.dart';
import '../utils/history.dart';
import 'advanced_mode.dart';
import 'calculator_mode.dart';
import 'simple_mode.dart';

//this widget class determines which screen to push (simple or advanced)
class CalculatorModeViewRebuilder extends ConsumerStatefulWidget {
const CalculatorModeViewRebuilder({Key? key}) : super(key: key);

Expand Down
117 changes: 116 additions & 1 deletion lib/src/ui/bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../utils/history.dart';

class BottomSheet extends ConsumerStatefulWidget {
const BottomSheet({Key? key}) : super(key: key);

Expand All @@ -11,6 +14,118 @@ class BottomSheet extends ConsumerStatefulWidget {
class _BottomSheetState extends ConsumerState<BottomSheet> {
@override
Widget build(BuildContext context) {
return Container();
return Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('History',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary)),
NeumorphicButton(
style: NeumorphicStyle(
color: Theme.of(context).scaffoldBackgroundColor,
shadowDarkColor: Theme.of(context).colorScheme.onBackground,
shadowLightColor: Theme.of(context).colorScheme.onSurface,
boxShape:
NeumorphicBoxShape.roundRect(BorderRadius.circular(10)),
),
onPressed: () async {
await HistoryDatabase.instance
.deleteHistory()
.then((value) => setState(() {}));
},
child: Center(
child: Icon(
Icons.delete_rounded,
color: Theme.of(context).colorScheme.secondary,
),
))
],
),
),
Expanded(
child: Neumorphic(
margin: const EdgeInsets.all(12.0),
padding: const EdgeInsets.symmetric(vertical: 15.0),
style: NeumorphicStyle(
depth: -5,
color: Theme.of(context).scaffoldBackgroundColor,
shadowDarkColorEmboss: Theme.of(context).colorScheme.onBackground,
shadowLightColorEmboss: Theme.of(context).colorScheme.onSurface,
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(20)),
),
child: FutureBuilder<List<Map<String, dynamic>>>(
future: HistoryDatabase.instance.getHistory(),
builder: (context, snapshot) {
if (snapshot.hasData) {
//if history is empty
final history = snapshot.data as List<Map<String, dynamic>>;
if (snapshot.data!.isEmpty) {
return Center(
child: Text('Nothing to show :(',
style: TextStyle(
fontSize: 20,
color:
Theme.of(context).colorScheme.secondary)),
);
}
return ListView.separated(
itemCount: history.length,
separatorBuilder: (BuildContext context, int index) =>
Divider(color: Theme.of(context).colorScheme.primary),
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
final historyIndex = history[index];
return Padding(
padding:
const EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SelectableText(
historyIndex['resultExpr'].toString(),
maxLines: 1,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.colorScheme
.secondary)),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SelectableText(
'= ${historyIndex['result']}',
maxLines: 1,
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Theme.of(context)
.colorScheme
.secondary)),
),
],
),
);
},
);
} else {
return const Center(
child: CircularProgressIndicator(
color: Colors.black,
));
}
}),
),
),
],
);
}
}
80 changes: 29 additions & 51 deletions lib/src/ui/common_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,15 @@ class _CommonDrawerState extends ConsumerState<CommonDrawer> {
.changeTheme(ThemeMode.system);
await _prefs.setInt('theme_mode', 0);
},
child: Container(
width: 24,
height: 24,
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
child: Icon(
Icons.screenshot,
color: themeController.currentTheme ==
ThemeMode.system
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context)
.colorScheme
.surface,
)),
child: Icon(
Icons.screenshot,
color: themeController.currentTheme ==
ThemeMode.system
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context).colorScheme.surface,
),
),
Padding(
padding: EdgeInsets.symmetric(
Expand All @@ -247,23 +239,17 @@ class _CommonDrawerState extends ConsumerState<CommonDrawer> {
.changeTheme(ThemeMode.light);
await _prefs.setInt('theme_mode', 1);
},
child: Container(
width: 24,
height: 24,
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
child: Icon(
Icons.wb_sunny,
color: themeController.currentTheme ==
ThemeMode.light
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context)
.colorScheme
.surface,
)),
child: Icon(
Icons.wb_sunny,
color: themeController.currentTheme ==
ThemeMode.light
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context)
.colorScheme
.surface,
),
),
),
InkWell(
Expand All @@ -279,23 +265,15 @@ class _CommonDrawerState extends ConsumerState<CommonDrawer> {
themeController.changeTheme(ThemeMode.dark);
await _prefs.setInt('theme_mode', 2);
},
child: Container(
width: 24,
height: 24,
decoration: const BoxDecoration(
shape: BoxShape.circle,
),
child: Icon(
Icons.brightness_3,
color: themeController.currentTheme ==
ThemeMode.dark
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context)
.colorScheme
.surface,
)),
child: Icon(
Icons.brightness_3,
color: themeController.currentTheme ==
ThemeMode.dark
? Theme.of(context)
.colorScheme
.secondary
: Theme.of(context).colorScheme.surface,
),
),
]);
},
Expand Down
11 changes: 7 additions & 4 deletions lib/src/utils/button_press.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:math_expressions/math_expressions.dart';

import '../../main.dart';
import 'history.dart';

//class responsible for all the buttons presses and calculations
class ButtonPress {
ButtonPress() {
cm.bindVariable(pi, Number(math.pi));
Expand Down Expand Up @@ -35,8 +37,6 @@ class ButtonPress {
final moreThanOneCharExpr = RegExp(r'(log\(|sin\(|cos\(|tan\()$');

int bracketCount = 0; //keeps track of currently open brackets
int sinTanCosBracketCount =
0; //keeps track of open trigonometric function brackets

buttonPressed(String btnVal, WidgetRef ref) {
try {
Expand Down Expand Up @@ -73,7 +73,7 @@ class ButtonPress {
}
//equals to
else if (btnVal == '=') {
if (bracketCount > 0 || sinTanCosBracketCount > 0) {
if (bracketCount > 0) {
for (int i = 0; i < bracketCount; i++) {
_expression += ')';
}
Expand All @@ -92,6 +92,8 @@ class ButtonPress {
: _expression;
ref.watch(calculatorDisplayDirectionProvider.state).state = false;
ref.read(expressionProvider.state).state = _expression;
HistoryDatabase.instance
.addHistory(ref.read(historyProvider.state).state, _expression);
}
}
//plus-minus operator
Expand Down Expand Up @@ -294,7 +296,8 @@ class ButtonPress {
}
ref.read(expressionProvider.state).state = 'ERROR';
Timer(const Duration(seconds: 1), () {
ref.read(expressionProvider.state).state = '';
_expression = '';
ref.read(expressionProvider.state).state = _expression;
});
}
}
Expand Down
Loading

0 comments on commit 285d866

Please sign in to comment.