Updated calculator demo (#4363)
This commit is contained in:
parent
60e7535b58
commit
df1c158e0b
@ -121,6 +121,7 @@ class _CalculatorState extends State<Calculator> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
// Give the key-pad 3/5 of the vertical space and the display 2/5.
|
// Give the key-pad 3/5 of the vertical space and the display 2/5.
|
||||||
new CalcDisplay(2, _expression.toString()),
|
new CalcDisplay(2, _expression.toString()),
|
||||||
|
new Divider(height: 1.0),
|
||||||
new KeyPad(3, calcState: this)
|
new KeyPad(3, calcState: this)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -141,7 +142,7 @@ class CalcDisplay extends StatelessWidget {
|
|||||||
child: new Center(
|
child: new Center(
|
||||||
child: new Text(
|
child: new Text(
|
||||||
_contents,
|
_contents,
|
||||||
style: const TextStyle(color: Colors.black, fontSize: 24.0)
|
style: const TextStyle(fontSize: 24.0)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -156,14 +157,22 @@ class KeyPad extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Flexible(
|
return new Theme(
|
||||||
|
data: new ThemeData(
|
||||||
|
primarySwatch: Colors.purple,
|
||||||
|
brightness: ThemeBrightness.dark
|
||||||
|
),
|
||||||
|
child: new Flexible(
|
||||||
flex: _flex,
|
flex: _flex,
|
||||||
|
child: new Material(
|
||||||
child: new Row(
|
child: new Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new MainKeyPad(calcState: calcState),
|
new MainKeyPad(calcState: calcState),
|
||||||
new OpKeyPad(calcState: calcState),
|
new OpKeyPad(calcState: calcState),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,9 +189,6 @@ class MainKeyPad extends StatelessWidget {
|
|||||||
// and the op keypad have sizes proportional to their number of
|
// and the op keypad have sizes proportional to their number of
|
||||||
// columns.
|
// columns.
|
||||||
flex: 3,
|
flex: 3,
|
||||||
child: new Material(
|
|
||||||
elevation: 12,
|
|
||||||
color: Colors.grey[800],
|
|
||||||
child: new Column(
|
child: new Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new KeyRow(<Widget>[
|
new KeyRow(<Widget>[
|
||||||
@ -207,7 +213,6 @@ class MainKeyPad extends StatelessWidget {
|
|||||||
])
|
])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,10 +224,10 @@ class OpKeyPad extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final ThemeData themeData = Theme.of(context);
|
||||||
return new Flexible(
|
return new Flexible(
|
||||||
child: new Material(
|
child: new Material(
|
||||||
elevation: 24,
|
color: themeData.backgroundColor,
|
||||||
color: Colors.grey[700],
|
|
||||||
child: new Column(
|
child: new Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new CalcKey('\u232B', calcState.handleDelTap),
|
new CalcKey('\u232B', calcState.handleDelTap),
|
||||||
@ -260,18 +265,19 @@ class CalcKey extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final Orientation orientation = MediaQuery.of(context).orientation;
|
||||||
return new Flexible(
|
return new Flexible(
|
||||||
// child: new Container(
|
|
||||||
child: new InkResponse(
|
child: new InkResponse(
|
||||||
onTap: this.onTap,
|
onTap: this.onTap,
|
||||||
child: new Center(
|
child: new Center(
|
||||||
child: new Text(
|
child: new Text(
|
||||||
this.text,
|
this.text,
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 32.0)
|
style: new TextStyle(
|
||||||
|
fontSize: (orientation == Orientation.portrait) ? 32.0 : 24.0
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
// )
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user