mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-05-17 21:15:54 +08:00
🚧 remove new keyword to get inline with dart 2 code standard.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(title: 'Tip Calculator', home: new TipCalculator()));
|
||||
runApp(MaterialApp(title: 'Tip Calculator', home: TipCalculator()));
|
||||
}
|
||||
|
||||
class TipCalculator extends StatelessWidget {
|
||||
@ -11,7 +11,7 @@ class TipCalculator extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Create first input field
|
||||
TextField billAmountField = new TextField(
|
||||
TextField billAmountField = TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
try {
|
||||
@ -20,12 +20,12 @@ class TipCalculator extends StatelessWidget {
|
||||
billAmount = 0.0;
|
||||
}
|
||||
},
|
||||
decoration: new InputDecoration(labelText: "Bill amount(\$)"),
|
||||
decoration: InputDecoration(labelText: "Bill amount(\$)"),
|
||||
);
|
||||
|
||||
// Create another input field
|
||||
TextField tipPercentageField = new TextField(
|
||||
decoration: new InputDecoration(labelText: "Tip %", hintText: "15"),
|
||||
TextField tipPercentageField = TextField(
|
||||
decoration: InputDecoration(labelText: "Tip %", hintText: "15"),
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (String value) {
|
||||
try {
|
||||
@ -36,30 +36,30 @@ class TipCalculator extends StatelessWidget {
|
||||
});
|
||||
|
||||
// Create button
|
||||
RaisedButton calculateButton = new RaisedButton(
|
||||
child: new Text("Calculate"),
|
||||
RaisedButton calculateButton = RaisedButton(
|
||||
child: Text("Calculate"),
|
||||
onPressed: () {
|
||||
// Calculate tip and total
|
||||
double calculatedTip = billAmount * tipPercentage / 100.0;
|
||||
double total = billAmount + calculatedTip;
|
||||
|
||||
// Generate dialog
|
||||
AlertDialog dialog = new AlertDialog(
|
||||
content: new Text("Tip: \$$calculatedTip \n"
|
||||
AlertDialog dialog = AlertDialog(
|
||||
content: Text("Tip: \$$calculatedTip \n"
|
||||
"Total: \$$total"));
|
||||
|
||||
// Show dialog
|
||||
showDialog(context: context, builder: (BuildContext context) => dialog);
|
||||
});
|
||||
|
||||
Container container = new Container(
|
||||
Container container = Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: new Column(
|
||||
child: Column(
|
||||
children: [billAmountField, tipPercentageField, calculateButton]));
|
||||
|
||||
AppBar appBar = new AppBar(title: new Text("Tip Calculator"));
|
||||
AppBar appBar = AppBar(title: Text("Tip Calculator"));
|
||||
|
||||
Scaffold scaffold = new Scaffold(appBar: appBar, body: container);
|
||||
Scaffold scaffold = Scaffold(appBar: appBar, body: container);
|
||||
return scaffold;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user