mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Update CI project list (#1583)
This commit is contained in:
@@ -80,8 +80,7 @@ class _MyContextMenuRegionState extends State<_MyContextMenuRegion> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ContextMenuRegion(
|
return ContextMenuRegion(
|
||||||
contextMenuBuilder: (context, primaryAnchor,
|
contextMenuBuilder: (context, primaryAnchor, [secondaryAnchor]) {
|
||||||
[secondaryAnchor]) {
|
|
||||||
return _MyCascadingContextMenu(
|
return _MyCascadingContextMenu(
|
||||||
anchor: primaryAnchor,
|
anchor: primaryAnchor,
|
||||||
showingMessage: _showMessage,
|
showingMessage: _showMessage,
|
||||||
|
|||||||
@@ -51,15 +51,14 @@ class CustomButtonsPage extends StatelessWidget {
|
|||||||
controller: _controller,
|
controller: _controller,
|
||||||
maxLines: 4,
|
maxLines: 4,
|
||||||
minLines: 2,
|
minLines: 2,
|
||||||
contextMenuBuilder:
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
(context, editableTextState) {
|
|
||||||
return AdaptiveTextSelectionToolbar(
|
return AdaptiveTextSelectionToolbar(
|
||||||
anchors: editableTextState.contextMenuAnchors,
|
anchors: editableTextState.contextMenuAnchors,
|
||||||
// Build the default buttons, but make them look custom.
|
// Build the default buttons, but make them look custom.
|
||||||
// Note that in a real project you may want to build
|
// Note that in a real project you may want to build
|
||||||
// different buttons depending on the platform.
|
// different buttons depending on the platform.
|
||||||
children: editableTextState.contextMenuButtonItems
|
children:
|
||||||
.map((buttonItem) {
|
editableTextState.contextMenuButtonItems.map((buttonItem) {
|
||||||
return CupertinoButton(
|
return CupertinoButton(
|
||||||
borderRadius: null,
|
borderRadius: null,
|
||||||
color: const Color(0xffaaaa00),
|
color: const Color(0xffaaaa00),
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import 'platform_selector.dart';
|
|||||||
|
|
||||||
class CustomMenuPage extends StatelessWidget {
|
class CustomMenuPage extends StatelessWidget {
|
||||||
CustomMenuPage({
|
CustomMenuPage({
|
||||||
Key? key,
|
super.key,
|
||||||
required this.onChangedPlatform,
|
required this.onChangedPlatform,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
static const String route = 'custom-menu';
|
static const String route = 'custom-menu';
|
||||||
static const String title = 'Custom Menu';
|
static const String title = 'Custom Menu';
|
||||||
@@ -49,8 +49,7 @@ class CustomMenuPage extends StatelessWidget {
|
|||||||
controller: _controller,
|
controller: _controller,
|
||||||
maxLines: 4,
|
maxLines: 4,
|
||||||
minLines: 2,
|
minLines: 2,
|
||||||
contextMenuBuilder:
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
(BuildContext context, EditableTextState editableTextState) {
|
|
||||||
return _MyContextMenu(
|
return _MyContextMenu(
|
||||||
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
|
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
|
||||||
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
|
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ class DefaultValuesPage extends StatelessWidget {
|
|||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
minLines: 2,
|
minLines: 2,
|
||||||
controller: _controllerCustom,
|
controller: _controllerCustom,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||||
anchors: editableTextState.contextMenuAnchors,
|
anchors: editableTextState.contextMenuAnchors,
|
||||||
buttonItems: <ContextMenuButtonItem>[
|
buttonItems: <ContextMenuButtonItem>[
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ class EmailButtonPage extends StatelessWidget {
|
|||||||
TextField(
|
TextField(
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
final TextEditingValue value =
|
final TextEditingValue value =
|
||||||
editableTextState.textEditingValue;
|
editableTextState.textEditingValue;
|
||||||
final List<ContextMenuButtonItem> buttonItems =
|
final List<ContextMenuButtonItem> buttonItems =
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ class FieldTypesPage extends StatelessWidget {
|
|||||||
CupertinoTextField(
|
CupertinoTextField(
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
controller: _cupertinoControllerFixed,
|
controller: _cupertinoControllerFixed,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
return AdaptiveTextSelectionToolbar.editableText(
|
return AdaptiveTextSelectionToolbar.editableText(
|
||||||
editableTextState: editableTextState,
|
editableTextState: editableTextState,
|
||||||
);
|
);
|
||||||
@@ -93,8 +92,7 @@ class FieldTypesPage extends StatelessWidget {
|
|||||||
CupertinoTextField(
|
CupertinoTextField(
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
controller: _cupertinoControllerForced,
|
controller: _cupertinoControllerForced,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
return DesktopTextSelectionToolbar(
|
return DesktopTextSelectionToolbar(
|
||||||
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
|
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
|
||||||
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
|
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
|
||||||
@@ -118,8 +116,7 @@ class FieldTypesPage extends StatelessWidget {
|
|||||||
// EditableText has no built-in gesture detection for
|
// EditableText has no built-in gesture detection for
|
||||||
// selection. A wrapper would have to implement
|
// selection. A wrapper would have to implement
|
||||||
// TextSelectionGestureDetectorBuilderDelegate, etc.
|
// TextSelectionGestureDetectorBuilderDelegate, etc.
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
return AdaptiveTextSelectionToolbar.editableText(
|
return AdaptiveTextSelectionToolbar.editableText(
|
||||||
editableTextState: editableTextState,
|
editableTextState: editableTextState,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ class FullPage extends StatelessWidget {
|
|||||||
Container(height: 20.0),
|
Container(height: 20.0),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
final TextEditingValue value =
|
final TextEditingValue value =
|
||||||
editableTextState.textEditingValue;
|
editableTextState.textEditingValue;
|
||||||
final List<ContextMenuButtonItem> buttonItems =
|
final List<ContextMenuButtonItem> buttonItems =
|
||||||
@@ -130,8 +129,7 @@ class FullPage extends StatelessWidget {
|
|||||||
// Build the default buttons, but make them look crazy.
|
// Build the default buttons, but make them look crazy.
|
||||||
// Note that in a real project you may want to build
|
// Note that in a real project you may want to build
|
||||||
// different buttons depending on the platform.
|
// different buttons depending on the platform.
|
||||||
children:
|
children: buttonItems.map((buttonItem) {
|
||||||
buttonItems.map((buttonItem) {
|
|
||||||
return CupertinoButton(
|
return CupertinoButton(
|
||||||
borderRadius: null,
|
borderRadius: null,
|
||||||
color: const Color(0xffaaaa00),
|
color: const Color(0xffaaaa00),
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class GlobalSelectionPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SelectionArea(
|
return SelectionArea(
|
||||||
contextMenuBuilder:
|
contextMenuBuilder: (context, selectableRegionState) {
|
||||||
(context, selectableRegionState) {
|
|
||||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||||
anchors: selectableRegionState.contextMenuAnchors,
|
anchors: selectableRegionState.contextMenuAnchors,
|
||||||
buttonItems: <ContextMenuButtonItem>[
|
buttonItems: <ContextMenuButtonItem>[
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
),
|
),
|
||||||
initialRoute: '/',
|
initialRoute: '/',
|
||||||
routes: <String, Widget Function(BuildContext)>{
|
routes: <String, Widget Function(BuildContext)>{
|
||||||
'/': (context) =>
|
'/': (context) => MyHomePage(onChangedPlatform: onChangedPlatform),
|
||||||
MyHomePage(onChangedPlatform: onChangedPlatform),
|
|
||||||
AnywherePage.route: (context) =>
|
AnywherePage.route: (context) =>
|
||||||
AnywherePage(onChangedPlatform: onChangedPlatform),
|
AnywherePage(onChangedPlatform: onChangedPlatform),
|
||||||
CustomButtonsPage.route: (context) =>
|
CustomButtonsPage.route: (context) =>
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ class ModifiedActionPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
final List<ContextMenuButtonItem> buttonItems =
|
final List<ContextMenuButtonItem> buttonItems =
|
||||||
editableTextState.contextMenuButtonItems;
|
editableTextState.contextMenuButtonItems;
|
||||||
// Modify the copy buttonItem to show a dialog after copying.
|
// Modify the copy buttonItem to show a dialog after copying.
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ class ReorderedButtonsPage extends StatelessWidget {
|
|||||||
TextField(
|
TextField(
|
||||||
controller: _controllerReordered,
|
controller: _controllerReordered,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
contextMenuBuilder: (context,
|
contextMenuBuilder: (context, editableTextState) {
|
||||||
editableTextState) {
|
|
||||||
// Reorder the button datas by type.
|
// Reorder the button datas by type.
|
||||||
final HashMap<ContextMenuButtonType, ContextMenuButtonItem>
|
final HashMap<ContextMenuButtonType, ContextMenuButtonItem>
|
||||||
buttonItemsMap =
|
buttonItemsMap =
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Can show and use the cascading menu',
|
testWidgets('Can show and use the cascading menu', (tester) async {
|
||||||
(tester) async {
|
|
||||||
await tester.pumpWidget(const MyApp());
|
await tester.pumpWidget(const MyApp());
|
||||||
|
|
||||||
// Navigate to the CascadingMenuPage example.
|
// Navigate to the CascadingMenuPage example.
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
|
import 'package:context_menus/custom_menu_page.dart';
|
||||||
|
import 'package:context_menus/main.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:context_menus/main.dart';
|
|
||||||
import 'package:context_menus/custom_menu_page.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Shows default buttons in a custom context menu',
|
testWidgets('Shows default buttons in a custom context menu', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
await tester.pumpWidget(const MyApp());
|
await tester.pumpWidget(const MyApp());
|
||||||
|
|
||||||
// Navigate to the CustomMenuPage example.
|
// Navigate to the CustomMenuPage example.
|
||||||
|
|||||||
@@ -10,108 +10,111 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'utils.dart';
|
import 'utils.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Selecting the email address shows a custom button',
|
testWidgets(
|
||||||
(tester) async {
|
'Selecting the email address shows a custom button',
|
||||||
await tester.pumpWidget(const MyApp());
|
(tester) async {
|
||||||
|
await tester.pumpWidget(const MyApp());
|
||||||
|
|
||||||
// Navigate to the EmailButtonPage example.
|
// Navigate to the EmailButtonPage example.
|
||||||
await tester.dragUntilVisible(
|
await tester.dragUntilVisible(
|
||||||
find.text(EmailButtonPage.title),
|
find.text(EmailButtonPage.title),
|
||||||
find.byType(ListView),
|
find.byType(ListView),
|
||||||
const Offset(0.0, -200.0),
|
const Offset(0.0, -200.0),
|
||||||
);
|
);
|
||||||
await tester.tap(find.text(EmailButtonPage.title));
|
await tester.tap(find.text(EmailButtonPage.title));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Select the first word, then right click to show the context menu.
|
// Select the first word, then right click to show the context menu.
|
||||||
expect(find.byType(TextField), findsOneWidget);
|
expect(find.byType(TextField), findsOneWidget);
|
||||||
await tester.tapAt(tester.getTopLeft(find.byType(EditableText)));
|
await tester.tapAt(tester.getTopLeft(find.byType(EditableText)));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||||
}
|
}
|
||||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
final TestGesture gesture1 = await tester.startGesture(
|
final TestGesture gesture1 = await tester.startGesture(
|
||||||
textOffsetToPosition(tester, 4),
|
textOffsetToPosition(tester, 4),
|
||||||
kind: PointerDeviceKind.mouse,
|
kind: PointerDeviceKind.mouse,
|
||||||
buttons: kSecondaryMouseButton,
|
buttons: kSecondaryMouseButton,
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await gesture1.up();
|
await gesture1.up();
|
||||||
await gesture1.removePointer();
|
await gesture1.removePointer();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// The context menu is shown, but no email button appears.
|
// The context menu is shown, but no email button appears.
|
||||||
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
||||||
expect(find.text('Send email'), findsNothing);
|
expect(find.text('Send email'), findsNothing);
|
||||||
switch (defaultTargetPlatform) {
|
switch (defaultTargetPlatform) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
expect(
|
expect(find.byType(CupertinoTextSelectionToolbarButton),
|
||||||
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(2));
|
findsNWidgets(2));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.macOS:
|
case TargetPlatform.macOS:
|
||||||
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
||||||
findsNWidgets(2));
|
findsNWidgets(2));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.android:
|
case TargetPlatform.android:
|
||||||
case TargetPlatform.fuchsia:
|
case TargetPlatform.fuchsia:
|
||||||
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3));
|
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(3));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.linux:
|
case TargetPlatform.linux:
|
||||||
case TargetPlatform.windows:
|
case TargetPlatform.windows:
|
||||||
expect(
|
expect(
|
||||||
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3));
|
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(3));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Click on "Copy" to hide the context menu.
|
// Click on "Copy" to hide the context menu.
|
||||||
await tester.tap(find.text('Copy'));
|
await tester.tap(find.text('Copy'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
|
||||||
|
|
||||||
// Select the email address, then right click it to show the context menu.
|
// Select the email address, then right click it to show the context menu.
|
||||||
for (int i = 0; i < 38; i++) {
|
for (int i = 0; i < 38; i++) {
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||||
}
|
}
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.shift);
|
||||||
for (int i = 0; i < 15; i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||||
}
|
}
|
||||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
await tester.sendKeyUpEvent(LogicalKeyboardKey.shift);
|
||||||
final TestGesture gesture2 = await tester.startGesture(
|
final TestGesture gesture2 = await tester.startGesture(
|
||||||
textOffsetToPosition(tester, 48),
|
textOffsetToPosition(tester, 48),
|
||||||
kind: PointerDeviceKind.mouse,
|
kind: PointerDeviceKind.mouse,
|
||||||
buttons: kSecondaryMouseButton,
|
buttons: kSecondaryMouseButton,
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await gesture2.up();
|
await gesture2.up();
|
||||||
await gesture2.removePointer();
|
await gesture2.removePointer();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// The context menu is shown, and the email button now appears.
|
// The context menu is shown, and the email button now appears.
|
||||||
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
expect(find.byType(AdaptiveTextSelectionToolbar), findsOneWidget);
|
||||||
expect(find.text('Send email'), findsOneWidget);
|
expect(find.text('Send email'), findsOneWidget);
|
||||||
switch (defaultTargetPlatform) {
|
switch (defaultTargetPlatform) {
|
||||||
case TargetPlatform.iOS:
|
case TargetPlatform.iOS:
|
||||||
expect(
|
expect(find.byType(CupertinoTextSelectionToolbarButton),
|
||||||
find.byType(CupertinoTextSelectionToolbarButton), findsNWidgets(3));
|
findsNWidgets(3));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.macOS:
|
case TargetPlatform.macOS:
|
||||||
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
expect(find.byType(CupertinoDesktopTextSelectionToolbarButton),
|
||||||
findsNWidgets(3));
|
findsNWidgets(3));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.android:
|
case TargetPlatform.android:
|
||||||
case TargetPlatform.fuchsia:
|
case TargetPlatform.fuchsia:
|
||||||
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4));
|
expect(find.byType(TextSelectionToolbarTextButton), findsNWidgets(4));
|
||||||
break;
|
break;
|
||||||
case TargetPlatform.linux:
|
case TargetPlatform.linux:
|
||||||
case TargetPlatform.windows:
|
case TargetPlatform.windows:
|
||||||
expect(
|
expect(
|
||||||
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4));
|
find.byType(DesktopTextSelectionToolbarButton), findsNWidgets(4));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
skip: true, // TODO(justinmc): Make this test pass and re-enable.
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(
|
|
||||||
const CalculatorApp(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(
|
|
||||||
const CalculatorApp(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const CalculatorApp(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const CalculatorApp(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
final String buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
this.buffer,
|
|
||||||
this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine(CalculatorState state) : super(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends StatelessWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Hello GDSC!',
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
style: TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
columnSizes: [1.fr],
|
|
||||||
rowSizes: [1.fr],
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 40),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
// TODO: implement build
|
|
||||||
throw UnimplementedError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
child: null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {},
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {}
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox(
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(label),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,225 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,228 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,229 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: OutlinedButton(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,234 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,235 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,236 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,243 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display
|
|
||||||
seven eight nine
|
|
||||||
four five six
|
|
||||||
one two three
|
|
||||||
zero point equals
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,252 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display display
|
|
||||||
seven eight nine divide
|
|
||||||
four five six multiply
|
|
||||||
one two three minus
|
|
||||||
zero point equals plus
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'plus',
|
|
||||||
op: (engine) => engine.addToBuffer('+'),
|
|
||||||
label: '+',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display display
|
|
||||||
seven eight nine divide
|
|
||||||
four five six multiply
|
|
||||||
one two three minus
|
|
||||||
zero point equals plus
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,262 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'plus',
|
|
||||||
op: (engine) => engine.addToBuffer('+'),
|
|
||||||
label: '+',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'minus',
|
|
||||||
op: (engine) => engine.addToBuffer('-'),
|
|
||||||
label: '-',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display display
|
|
||||||
seven eight nine divide
|
|
||||||
four five six multiply
|
|
||||||
one two three minus
|
|
||||||
zero point equals plus
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,267 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'plus',
|
|
||||||
op: (engine) => engine.addToBuffer('+'),
|
|
||||||
label: '+',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'minus',
|
|
||||||
op: (engine) => engine.addToBuffer('-'),
|
|
||||||
label: '-',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'multiply',
|
|
||||||
op: (engine) => engine.addToBuffer('*'),
|
|
||||||
label: '*',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display display
|
|
||||||
seven eight nine divide
|
|
||||||
four five six multiply
|
|
||||||
one two three minus
|
|
||||||
zero point equals plus
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,272 +0,0 @@
|
|||||||
// Copyright 2022 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:window_size/window_size.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
setWindowTitle('Simplistic Calculator');
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(
|
|
||||||
const ProviderScope(
|
|
||||||
child: CalculatorApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
|
||||||
class CalculatorState {
|
|
||||||
const CalculatorState({
|
|
||||||
required this.buffer,
|
|
||||||
required this.mode,
|
|
||||||
required this.error,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String buffer;
|
|
||||||
final CalculatorEngineMode mode;
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
CalculatorState copyWith({
|
|
||||||
String? buffer,
|
|
||||||
CalculatorEngineMode? mode,
|
|
||||||
String? error,
|
|
||||||
}) =>
|
|
||||||
CalculatorState(
|
|
||||||
buffer: buffer ?? this.buffer,
|
|
||||||
mode: mode ?? this.mode,
|
|
||||||
error: error ?? this.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CalculatorEngineMode { input, result }
|
|
||||||
|
|
||||||
class CalculatorEngine extends StateNotifier<CalculatorState> {
|
|
||||||
CalculatorEngine()
|
|
||||||
: super(
|
|
||||||
const CalculatorState(
|
|
||||||
buffer: '0',
|
|
||||||
mode: CalculatorEngineMode.result,
|
|
||||||
error: '',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
void addToBuffer(String str) {
|
|
||||||
if (state.mode == CalculatorEngineMode.result) {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: str,
|
|
||||||
mode: CalculatorEngineMode.input,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
state = state.copyWith(
|
|
||||||
buffer: state.buffer + str,
|
|
||||||
error: '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final calculatorStateProvider =
|
|
||||||
StateNotifierProvider<CalculatorEngine, CalculatorState>(
|
|
||||||
(_) => CalculatorEngine());
|
|
||||||
|
|
||||||
class ButtonDefinition {
|
|
||||||
const ButtonDefinition({
|
|
||||||
required this.areaName,
|
|
||||||
required this.label,
|
|
||||||
required this.op,
|
|
||||||
this.type = CalcButtonType.outlined,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String areaName;
|
|
||||||
final String label;
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final CalcButtonType type;
|
|
||||||
}
|
|
||||||
|
|
||||||
final buttonDefinitions = <ButtonDefinition>[
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'seven',
|
|
||||||
op: (engine) => engine.addToBuffer('7'),
|
|
||||||
label: '7',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'eight',
|
|
||||||
op: (engine) => engine.addToBuffer('8'),
|
|
||||||
label: '8',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'nine',
|
|
||||||
op: (engine) => engine.addToBuffer('9'),
|
|
||||||
label: '9',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'four',
|
|
||||||
op: (engine) => engine.addToBuffer('4'),
|
|
||||||
label: '4',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'five',
|
|
||||||
op: (engine) => engine.addToBuffer('5'),
|
|
||||||
label: '5',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'six',
|
|
||||||
op: (engine) => engine.addToBuffer('6'),
|
|
||||||
label: '6',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'one',
|
|
||||||
op: (engine) => engine.addToBuffer('1'),
|
|
||||||
label: '1',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'two',
|
|
||||||
op: (engine) => engine.addToBuffer('2'),
|
|
||||||
label: '2',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'three',
|
|
||||||
op: (engine) => engine.addToBuffer('3'),
|
|
||||||
label: '3',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'zero',
|
|
||||||
op: (engine) => engine.addToBuffer('0'),
|
|
||||||
label: '0',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'point',
|
|
||||||
op: (engine) => engine.addToBuffer('.'),
|
|
||||||
label: '.',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'equals',
|
|
||||||
op: (engine) {},
|
|
||||||
label: '=',
|
|
||||||
type: CalcButtonType.elevated,
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'plus',
|
|
||||||
op: (engine) => engine.addToBuffer('+'),
|
|
||||||
label: '+',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'minus',
|
|
||||||
op: (engine) => engine.addToBuffer('-'),
|
|
||||||
label: '-',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'multiply',
|
|
||||||
op: (engine) => engine.addToBuffer('*'),
|
|
||||||
label: '*',
|
|
||||||
),
|
|
||||||
ButtonDefinition(
|
|
||||||
areaName: 'divide',
|
|
||||||
op: (engine) => engine.addToBuffer('/'),
|
|
||||||
label: '/',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
class CalculatorApp extends ConsumerWidget {
|
|
||||||
const CalculatorApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final state = ref.watch(calculatorStateProvider);
|
|
||||||
|
|
||||||
return MaterialApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Scaffold(
|
|
||||||
body: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: LayoutGrid(
|
|
||||||
areas: '''
|
|
||||||
display display display display
|
|
||||||
seven eight nine divide
|
|
||||||
four five six multiply
|
|
||||||
one two three minus
|
|
||||||
zero point equals plus
|
|
||||||
''',
|
|
||||||
columnSizes: [1.fr, 1.fr, 1.fr, 1.fr],
|
|
||||||
rowSizes: [
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
1.fr,
|
|
||||||
],
|
|
||||||
children: [
|
|
||||||
NamedAreaGridPlacement(
|
|
||||||
areaName: 'display',
|
|
||||||
child: SizedBox.expand(
|
|
||||||
child: Text(
|
|
||||||
state.buffer,
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: const TextStyle(fontSize: 80),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...buttonDefinitions.map(
|
|
||||||
(definition) => NamedAreaGridPlacement(
|
|
||||||
areaName: definition.areaName,
|
|
||||||
child: CalcButton(
|
|
||||||
label: definition.label,
|
|
||||||
op: definition.op,
|
|
||||||
type: definition.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CalculatorEngineCallback = void Function(CalculatorEngine engine);
|
|
||||||
|
|
||||||
enum CalcButtonType { outlined, elevated }
|
|
||||||
|
|
||||||
class CalcButton extends ConsumerWidget {
|
|
||||||
const CalcButton({
|
|
||||||
Key? key,
|
|
||||||
required this.op,
|
|
||||||
required this.label,
|
|
||||||
required this.type,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
final CalculatorEngineCallback op;
|
|
||||||
final String label;
|
|
||||||
final CalcButtonType type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final buttonConstructor = type == CalcButtonType.elevated
|
|
||||||
? ElevatedButton.new
|
|
||||||
: OutlinedButton.new;
|
|
||||||
|
|
||||||
return SizedBox.expand(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
child: buttonConstructor(
|
|
||||||
onPressed: () => op(ref.read(calculatorStateProvider.notifier)),
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 40, color: Colors.black54),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user