diff --git a/examples/calculator/.gitignore b/examples/calculator/.gitignore
deleted file mode 100644
index 14c7d4c3f7..0000000000
--- a/examples/calculator/.gitignore
+++ /dev/null
@@ -1,9 +0,0 @@
-.DS_Store
-.atom/
-.idea
-.packages
-.pub/
-build/
-ios/.generated/
-packages
-pubspec.lock
diff --git a/examples/calculator/README.md b/examples/calculator/README.md
deleted file mode 100644
index f247b5cf60..0000000000
--- a/examples/calculator/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# calculator
-
-A Material Design Calculator written in Flutter.
-
-## Getting Started
-
-For help getting started with Flutter, view our online
-[documentation](http://flutter.io/).
diff --git a/examples/calculator/android/AndroidManifest.xml b/examples/calculator/android/AndroidManifest.xml
deleted file mode 100644
index 8a7cc4839e..0000000000
--- a/examples/calculator/android/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/examples/calculator/android/res/mipmap-hdpi/ic_launcher.png b/examples/calculator/android/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index f0a55cda78..0000000000
Binary files a/examples/calculator/android/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/examples/calculator/android/res/mipmap-mdpi/ic_launcher.png b/examples/calculator/android/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index eb98dc451d..0000000000
Binary files a/examples/calculator/android/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/examples/calculator/android/res/mipmap-xhdpi/ic_launcher.png b/examples/calculator/android/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index f1783dbbf3..0000000000
Binary files a/examples/calculator/android/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/examples/calculator/android/res/mipmap-xxhdpi/ic_launcher.png b/examples/calculator/android/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 46828a290a..0000000000
Binary files a/examples/calculator/android/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/examples/calculator/android/res/mipmap-xxxhdpi/ic_launcher.png b/examples/calculator/android/res/mipmap-xxxhdpi/ic_launcher.png
deleted file mode 100644
index a5276715d9..0000000000
Binary files a/examples/calculator/android/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/examples/calculator/flutter.yaml b/examples/calculator/flutter.yaml
deleted file mode 100644
index f52ac623ce..0000000000
--- a/examples/calculator/flutter.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-name: calculator
-uses-material-design: true
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Contents.json
deleted file mode 100644
index 363d1c4ce4..0000000000
--- a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Contents.json
+++ /dev/null
@@ -1,142 +0,0 @@
-{
- "images" : [
- {
- "size" : "29x29",
- "idiom" : "iphone",
- "filename" : "Icon-Small@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "29x29",
- "idiom" : "iphone",
- "filename" : "Icon-Small@3x.png",
- "scale" : "3x"
- },
- {
- "size" : "40x40",
- "idiom" : "iphone",
- "filename" : "Icon-Small-40@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "40x40",
- "idiom" : "iphone",
- "filename" : "Icon-Small-40@3x.png",
- "scale" : "3x"
- },
- {
- "size" : "60x60",
- "idiom" : "iphone",
- "filename" : "Icon-60@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "60x60",
- "idiom" : "iphone",
- "filename" : "Icon-60@3x.png",
- "scale" : "3x"
- },
- {
- "size" : "29x29",
- "idiom" : "ipad",
- "filename" : "Icon-Small.png",
- "scale" : "1x"
- },
- {
- "size" : "29x29",
- "idiom" : "ipad",
- "filename" : "Icon-Small@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "40x40",
- "idiom" : "ipad",
- "filename" : "Icon-Small-40.png",
- "scale" : "1x"
- },
- {
- "size" : "40x40",
- "idiom" : "ipad",
- "filename" : "Icon-Small-40@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "76x76",
- "idiom" : "ipad",
- "filename" : "Icon-76.png",
- "scale" : "1x"
- },
- {
- "size" : "76x76",
- "idiom" : "ipad",
- "filename" : "Icon-76@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "83.5x83.5",
- "idiom" : "ipad",
- "filename" : "Icon-83.5@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "16x16",
- "idiom" : "mac",
- "filename" : "icon_16x16.png",
- "scale" : "1x"
- },
- {
- "size" : "16x16",
- "idiom" : "mac",
- "filename" : "icon_16x16@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "32x32",
- "idiom" : "mac",
- "filename" : "icon_32x32.png",
- "scale" : "1x"
- },
- {
- "size" : "32x32",
- "idiom" : "mac",
- "filename" : "icon_32x32@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "128x128",
- "idiom" : "mac",
- "filename" : "icon_128x128.png",
- "scale" : "1x"
- },
- {
- "size" : "128x128",
- "idiom" : "mac",
- "filename" : "icon_128x128@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "256x256",
- "idiom" : "mac",
- "filename" : "icon_256x256.png",
- "scale" : "1x"
- },
- {
- "size" : "256x256",
- "idiom" : "mac",
- "filename" : "icon_256x256@2x.png",
- "scale" : "2x"
- },
- {
- "size" : "512x512",
- "idiom" : "mac",
- "filename" : "icon_512x512.png",
- "scale" : "1x"
- },
- {
- "size" : "512x512",
- "idiom" : "mac",
- "filename" : "icon_512x512@2x.png",
- "scale" : "2x"
- }
- ]
-}
\ No newline at end of file
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png
deleted file mode 100644
index 9996f5e598..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png
deleted file mode 100644
index 7a543edbdd..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76.png
deleted file mode 100644
index 05a8268104..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76@2x.png
deleted file mode 100644
index bfbca28f5d..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-76@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-83.5@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-83.5@2x.png
deleted file mode 100644
index c924b8e497..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-83.5@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40.png
deleted file mode 100644
index 3006f1d348..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png
deleted file mode 100644
index 5f7d22d364..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png
deleted file mode 100644
index 9996f5e598..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small.png
deleted file mode 100644
index 3433da1196..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png
deleted file mode 100644
index f7f9f16d1b..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png
deleted file mode 100644
index e9c23601cf..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128.png
deleted file mode 100644
index dd5fccb0a9..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png
deleted file mode 100644
index 1909e27511..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16.png
deleted file mode 100644
index 40a701b514..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png
deleted file mode 100644
index 06c1a80560..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256.png
deleted file mode 100644
index 1909e27511..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png
deleted file mode 100644
index 69c96ef1e2..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32.png
deleted file mode 100644
index 06c1a80560..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png
deleted file mode 100644
index 0f94371460..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512.png
deleted file mode 100644
index 69c96ef1e2..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512.png and /dev/null differ
diff --git a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png b/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png
deleted file mode 100644
index 1d6355f58c..0000000000
Binary files a/examples/calculator/ios/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png and /dev/null differ
diff --git a/examples/calculator/ios/Info.plist b/examples/calculator/ios/Info.plist
deleted file mode 100644
index 114564110e..0000000000
--- a/examples/calculator/ios/Info.plist
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
-
- CFBundleDevelopmentRegion
- en
- CFBundleExecutable
- Runner
- CFBundleIdentifier
- com.yourcompany.calculator
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- calculator
- CFBundlePackageType
- APPL
- CFBundleShortVersionString
- 1.0
- CFBundleSignature
- ????
- CFBundleVersion
- 1
- LSRequiresIPhoneOS
-
- UILaunchStoryboardName
- LaunchScreen
- UIRequiredDeviceCapabilities
-
- arm64
-
- UISupportedInterfaceOrientations
-
- UIInterfaceOrientationPortrait
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
-
- UISupportedInterfaceOrientations~ipad
-
- UIInterfaceOrientationPortrait
- UIInterfaceOrientationPortraitUpsideDown
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
-
- UIViewControllerBasedStatusBarAppearance
-
-
-
diff --git a/examples/calculator/ios/LaunchScreen.storyboard b/examples/calculator/ios/LaunchScreen.storyboard
deleted file mode 100644
index 78686cd075..0000000000
--- a/examples/calculator/ios/LaunchScreen.storyboard
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/examples/calculator/pubspec.yaml b/examples/calculator/pubspec.yaml
deleted file mode 100644
index cad2f30978..0000000000
--- a/examples/calculator/pubspec.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
-name: calculator
-description: A new flutter project.
-dependencies:
- flutter:
- path: ../../packages/flutter
-
-dev_dependencies:
- test: any # flutter_test provides the version constraints
- flutter_test:
- path: ../../packages/flutter_test
- flutter_driver:
- path: ../../packages/flutter_driver
diff --git a/examples/calculator/lib/main.dart b/examples/flutter_gallery/lib/calculator/interface.dart
similarity index 55%
rename from examples/calculator/lib/main.dart
rename to examples/flutter_gallery/lib/calculator/interface.dart
index 21ee62fa99..beced67104 100644
--- a/examples/calculator/lib/main.dart
+++ b/examples/flutter_gallery/lib/calculator/interface.dart
@@ -4,38 +4,32 @@
import 'package:flutter/material.dart';
-import 'calc_expression.dart';
-
-// A calculator application.
-void main() {
- runApp(new MaterialApp(
- title: 'Calculator',
- theme: new ThemeData(primarySwatch: Colors.blue),
- home: new Calculator()));
-}
+import 'logic.dart';
class Calculator extends StatefulWidget {
Calculator({Key key}) : super(key: key);
+ static const String routeName = '/calculator';
+
@override
_CalculatorState createState() => new _CalculatorState();
}
class _CalculatorState extends State {
- // As the user taps keys we update the current |_expression| and we also
- // keep a stack of previous expressions so we can return to earlier states
- // when the user hits the DEL key.
+ /// As the user taps keys we update the current `_expression` and we also
+ /// keep a stack of previous expressions so we can return to earlier states
+ /// when the user hits the DEL key.
final List _expressionStack = [];
CalcExpression _expression = new CalcExpression.Empty();
- // Make |expression| the current expression and push the previous current
+ // Make `expression` the current expression and push the previous current
// expression onto the stack.
void pushExpression(CalcExpression expression) {
_expressionStack.add(_expression);
_expression = expression;
}
- // Pop the top expression off of the stack and make it the current expression.
+ /// Pop the top expression off of the stack and make it the current expression.
void popCalcExpression() {
if (_expressionStack.length > 0) {
_expression = _expressionStack.removeLast();
@@ -44,7 +38,7 @@ class _CalculatorState extends State {
}
}
- // Set |resultExpression| to the currrent expression and clear the stack.
+ /// Set `resultExpression` to the currrent expression and clear the stack.
void setResult(CalcExpression resultExpression) {
_expressionStack.clear();
_expression = resultExpression;
@@ -69,8 +63,7 @@ class _CalculatorState extends State {
}
void handlePlusTap() {
- final CalcExpression expression =
- _expression.appendOperation(Operation.Addition);
+ final CalcExpression expression = _expression.appendOperation(Operation.Addition);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -88,8 +81,7 @@ class _CalculatorState extends State {
}
void handleMultTap() {
- final CalcExpression expression =
- _expression.appendOperation(Operation.Multiplication);
+ final CalcExpression expression = _expression.appendOperation(Operation.Multiplication);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -98,8 +90,7 @@ class _CalculatorState extends State {
}
void handleDivTap() {
- final CalcExpression expression =
- _expression.appendOperation(Operation.Division);
+ final CalcExpression expression = _expression.appendOperation(Operation.Division);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -125,13 +116,15 @@ class _CalculatorState extends State {
@override
Widget build(BuildContext context) {
return new Scaffold(
- appBar: new AppBar(title: new Text('Calculator')),
- body: new Column(children: [
- // Give the key-pad 3/5 of the vertical space and the display
- // 2/5.
+ appBar: new AppBar(title: new Text('Calculator')),
+ body: new Column(
+ children: [
+ // Give the key-pad 3/5 of the vertical space and the display 2/5.
new CalcDisplay(2, _expression.toString()),
new KeyPad(3, calcState: this)
- ]));
+ ]
+ )
+ );
}
}
@@ -144,9 +137,14 @@ class CalcDisplay extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Flexible(
- flex: _flex,
- child: new Center(child: new Text(_contents,
- style: const TextStyle(color: Colors.black, fontSize: 24.0))));
+ flex: _flex,
+ child: new Center(
+ child: new Text(
+ _contents,
+ style: const TextStyle(color: Colors.black, fontSize: 24.0)
+ )
+ )
+ );
}
}
@@ -159,11 +157,14 @@ class KeyPad extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Flexible(
- flex: _flex,
- child: new Row(children: [
+ flex: _flex,
+ child: new Row(
+ children: [
new MainKeyPad(calcState: calcState),
new OpKeyPad(calcState: calcState),
- ]));
+ ]
+ )
+ );
}
}
@@ -175,36 +176,39 @@ class MainKeyPad extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Flexible(
- // We set flex equal to the number of columns so that the main keypad
- // and the op keypad have sizes proportional to their number of
- // columns.
- flex: 3,
- child: new Material(
- type: MaterialType.canvas,
- elevation: 12,
- color: Colors.grey[800],
- child: new Column(children: [
- new KeyRow([
- new NumberKey(7, calcState),
- new NumberKey(8, calcState),
- new NumberKey(9, calcState)
- ]),
- new KeyRow([
- new NumberKey(4, calcState),
- new NumberKey(5, calcState),
- new NumberKey(6, calcState)
- ]),
- new KeyRow([
- new NumberKey(1, calcState),
- new NumberKey(2, calcState),
- new NumberKey(3, calcState)
- ]),
- new KeyRow([
- new CalcKey('.', calcState.handlePointTap),
- new NumberKey(0, calcState),
- new CalcKey('=', calcState.handleEqualsTap),
- ])
- ])));
+ // We set flex equal to the number of columns so that the main keypad
+ // and the op keypad have sizes proportional to their number of
+ // columns.
+ flex: 3,
+ child: new Material(
+ elevation: 12,
+ color: Colors.grey[800],
+ child: new Column(
+ children: [
+ new KeyRow([
+ new NumberKey(7, calcState),
+ new NumberKey(8, calcState),
+ new NumberKey(9, calcState)
+ ]),
+ new KeyRow([
+ new NumberKey(4, calcState),
+ new NumberKey(5, calcState),
+ new NumberKey(6, calcState)
+ ]),
+ new KeyRow([
+ new NumberKey(1, calcState),
+ new NumberKey(2, calcState),
+ new NumberKey(3, calcState)
+ ]),
+ new KeyRow([
+ new CalcKey('.', calcState.handlePointTap),
+ new NumberKey(0, calcState),
+ new CalcKey('=', calcState.handleEqualsTap),
+ ])
+ ]
+ )
+ )
+ );
}
}
@@ -215,17 +219,21 @@ class OpKeyPad extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return new Flexible(child: new Material(
- type: MaterialType.canvas,
+ return new Flexible(
+ child: new Material(
elevation: 24,
color: Colors.grey[700],
- child: new Column(children: [
- new CalcKey('DEL', calcState.handleDelTap),
- new CalcKey('\u00F7', calcState.handleDivTap),
- new CalcKey('\u00D7', calcState.handleMultTap),
- new CalcKey('-', calcState.handleMinusTap),
- new CalcKey('+', calcState.handlePlusTap)
- ])));
+ child: new Column(
+ children: [
+ new CalcKey('\u232B', calcState.handleDelTap),
+ new CalcKey('\u00F7', calcState.handleDivTap),
+ new CalcKey('\u00D7', calcState.handleMultTap),
+ new CalcKey('-', calcState.handleMinusTap),
+ new CalcKey('+', calcState.handlePlusTap)
+ ]
+ )
+ )
+ );
}
}
@@ -236,28 +244,41 @@ class KeyRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return new Flexible(child: new Row(
- mainAxisAlignment: MainAxisAlignment.center, children: this.keys));
+ return new Flexible(
+ child: new Row(
+ mainAxisAlignment: MainAxisAlignment.center, children: this.keys
+ )
+ );
}
}
class CalcKey extends StatelessWidget {
+ CalcKey(this.text, this.onTap);
+
final String text;
final GestureTapCallback onTap;
- CalcKey(this.text, this.onTap);
@override
Widget build(BuildContext context) {
- return new Flexible(child: new Container(child: new InkResponse(
- onTap: this.onTap,
- child: new Center(child: new Text(this.text,
- style: const TextStyle(color: Colors.white, fontSize: 32.0))))));
+ return new Flexible(
+// child: new Container(
+ child: new InkResponse(
+ onTap: this.onTap,
+ child: new Center(
+ child: new Text(
+ this.text,
+ style: const TextStyle(color: Colors.white, fontSize: 32.0)
+ )
+ )
+ )
+// )
+ );
}
}
class NumberKey extends CalcKey {
NumberKey(int value, _CalculatorState calcState)
- : super('$value', () {
- calcState.handleNumberTap(value);
- });
+ : super('$value', () {
+ calcState.handleNumberTap(value);
+ });
}
diff --git a/examples/calculator/lib/calc_expression.dart b/examples/flutter_gallery/lib/calculator/logic.dart
similarity index 89%
rename from examples/calculator/lib/calc_expression.dart
rename to examples/flutter_gallery/lib/calculator/logic.dart
index f7adc8e847..e73a3fca22 100644
--- a/examples/calculator/lib/calc_expression.dart
+++ b/examples/flutter_gallery/lib/calculator/logic.dart
@@ -35,8 +35,10 @@ class FloatToken extends NumberToken {
static double _parse(String stringRep) {
String toParse = stringRep;
- if (toParse.startsWith('.')) toParse = '0' + toParse;
- if (toParse.endsWith('.')) toParse = toParse + '0';
+ if (toParse.startsWith('.'))
+ toParse = '0' + toParse;
+ if (toParse.endsWith('.'))
+ toParse = toParse + '0';
return double.parse(toParse);
}
}
@@ -45,11 +47,12 @@ class FloatToken extends NumberToken {
class ResultToken extends NumberToken {
ResultToken(num number) : super.fromNumber(round(number));
- // rounds |number| to 14 digits of precision. A double precision
- // floating point number is guaranteed to have at least this many
- // decimal digits of precision.
+ /// rounds `number` to 14 digits of precision. A double precision
+ /// floating point number is guaranteed to have at least this many
+ /// decimal digits of precision.
static num round(num number) {
- if (number is int) return number;
+ if (number is int)
+ return number;
return double.parse(number.toStringAsPrecision(14));
}
}
@@ -64,8 +67,8 @@ enum Operation { Addition, Subtraction, Multiplication, Division }
/// A token that represents an arithmetic operation symbol.
class OperationToken extends ExpressionToken {
OperationToken(Operation operation)
- : this.operation = operation,
- super(opString(operation));
+ : operation = operation,
+ super(opString(operation));
Operation operation;
@@ -86,18 +89,23 @@ class OperationToken extends ExpressionToken {
/// As the user taps different keys the current expression can be in one
/// of several states.
enum ExpressionState {
- // The expression is empty or an operation symbol was just entered.
- // A new number must be started now.
+ /// The expression is empty or an operation symbol was just entered.
+ /// A new number must be started now.
Start,
- // A minus sign was entered as a leading negative prefix.
+
+ /// A minus sign was entered as a leading negative prefix.
LeadingNeg,
- // We are in the midst of a number without a point.
+
+ /// We are in the midst of a number without a point.
Number,
- // A point was just entered.
+
+ /// A point was just entered.
Point,
- // We are in the midst of a number with a point.
+
+ /// We are in the midst of a number with a point.
NumberWithPoint,
- // A result is being displayed
+
+ /// A result is being displayed
Result,
}
@@ -112,21 +120,21 @@ class CalcExpression {
CalcExpression(this._list, this.state);
CalcExpression.Empty()
- : this(new List(), ExpressionState.Start);
+ : this([], ExpressionState.Start);
CalcExpression.Result(FloatToken result)
- : _list = new List(),
- state = ExpressionState.Result {
+ : _list = [],
+ state = ExpressionState.Result {
_list.add(result);
}
- // The tokens comprising the expression.
+ /// The tokens comprising the expression.
final List _list;
- // The state of the expression.
+ /// The state of the expression.
final ExpressionState state;
- // The string representation of the expression. This will be displayed
- // in the calculator's display panel.
+ /// The string representation of the expression. This will be displayed
+ /// in the calculator's display panel.
@override
String toString() {
StringBuffer buffer = new StringBuffer('');
@@ -296,9 +304,9 @@ class CalcExpression {
return new CalcExpression(outList, ExpressionState.Result);
}
- // Removes the next "term" from |list| and returns its numeric value.
- // A "term" is a sequence of number tokens separated by multiplication
- // and division symbols.
+ /// Removes the next "term" from `list` and returns its numeric value.
+ /// A "term" is a sequence of number tokens separated by multiplication
+ /// and division symbols.
static num removeNextTerm(List list) {
assert(list != null && list.length >= 1);
final NumberToken firstNumToken = list.removeAt(0);
diff --git a/examples/flutter_gallery/lib/gallery/app.dart b/examples/flutter_gallery/lib/gallery/app.dart
index 10b8758a9b..79175771dc 100644
--- a/examples/flutter_gallery/lib/gallery/app.dart
+++ b/examples/flutter_gallery/lib/gallery/app.dart
@@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
+import '../calculator/interface.dart';
import '../demo/all.dart';
import 'home.dart';
@@ -12,6 +13,7 @@ final Map kRoutes = {
WeatherDemo.routeName: (BuildContext context) => new WeatherDemo(),
FitnessDemo.routeName: (BuildContext context) => new FitnessDemo(),
DrawingDemo.routeName: (BuildContext context) => new DrawingDemo(),
+ Calculator.routeName: (BuildContext context) => new Calculator(),
FlexibleSpaceDemo.routeName: (BuildContext context) => new FlexibleSpaceDemo(),
TabsFabDemo.routeName: (BuildContext context) => new TabsFabDemo(),
ButtonsDemo.routeName: (BuildContext context) => new ButtonsDemo(),
diff --git a/examples/flutter_gallery/lib/gallery/home.dart b/examples/flutter_gallery/lib/gallery/home.dart
index d825a193b6..20830a646e 100644
--- a/examples/flutter_gallery/lib/gallery/home.dart
+++ b/examples/flutter_gallery/lib/gallery/home.dart
@@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
+import '../calculator/interface.dart';
import '../demo/all.dart';
import 'drawer.dart';
import 'header.dart';
@@ -76,6 +77,7 @@ class GalleryHomeState extends State {
new GalleryItem(title: 'Weather', routeName: WeatherDemo.routeName),
new GalleryItem(title: 'Fitness', routeName: FitnessDemo.routeName),
new GalleryItem(title: 'Fancy lines', routeName: DrawingDemo.routeName),
+ new GalleryItem(title: 'Calculator', routeName: Calculator.routeName),
new GalleryItem(title: 'Flexible space toolbar', routeName: FlexibleSpaceDemo.routeName),
new GalleryItem(title: 'Floating action button', routeName: TabsFabDemo.routeName),
]
diff --git a/examples/calculator/test/calc_expression_test.dart b/examples/flutter_gallery/test/calculator/logic.dart
similarity index 98%
rename from examples/calculator/test/calc_expression_test.dart
rename to examples/flutter_gallery/test/calculator/logic.dart
index 38f2ae4387..01d867a105 100644
--- a/examples/calculator/test/calc_expression_test.dart
+++ b/examples/flutter_gallery/test/calculator/logic.dart
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:calculator/calc_expression.dart';
+import 'package:flutter_gallery/calculator/logic.dart';
import 'package:test/test.dart';
void main() {
diff --git a/examples/calculator/test/smoke_test.dart b/examples/flutter_gallery/test/calculator/smoke_test.dart
similarity index 80%
rename from examples/calculator/test/smoke_test.dart
rename to examples/flutter_gallery/test/calculator/smoke_test.dart
index 6f184a8496..b555fdeb5d 100644
--- a/examples/calculator/test/smoke_test.dart
+++ b/examples/flutter_gallery/test/calculator/smoke_test.dart
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:calculator/main.dart' as calculator;
+import 'package:flutter_gallery/calculator/interface.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -14,9 +14,7 @@ void main() {
// We press the "1" and the "2" buttons and check that the display
// reads "12".
testWidgets('Flutter calculator app smoke test', (WidgetTester tester) async {
- calculator.main(); // builds the app and schedules a frame but doesn't trigger one
- await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
- await tester.pump(); // triggers a frame
+ await tester.pumpWidget(new Calculator());
Finder oneButton = find.widgetWithText(InkResponse, '1');
expect(oneButton, findsOneWidget);