diff options
Diffstat (limited to 'lib/main.dart')
| -rwxr-xr-x | lib/main.dart | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/lib/main.dart b/lib/main.dart index cf8e184..f6bbb92 100755 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,7 +11,7 @@ extension on SpeedUnit { SpeedUnit.milesPerHour => metersPerSecond * 2.236936,
};
- get acronym => switch (this) {
+ String get acronym => switch (this) {
SpeedUnit.kilometersPerHour => 'kmph',
SpeedUnit.milesPerHour => 'mph',
};
@@ -24,7 +24,6 @@ void main() { class MyApp extends StatelessWidget {
const MyApp({super.key});
- // This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
@@ -38,30 +37,19 @@ class MyApp extends StatelessWidget { brightness: Brightness.dark,
),
),
- home: const MyHomePage(title: 'Speedometer'),
+ home: HomePage(),
);
}
}
-class MyHomePage extends StatefulWidget {
- const MyHomePage({super.key, required this.title});
-
- // This widget is the home page of your application. It is stateful, meaning
- // that it has a State object (defined below) that contains fields that affect
- // how it looks.
-
- // This class is the configuration for the state. It holds the values (in this
- // case the title) provided by the parent (in this case the App widget) and
- // used by the build method of the State. Fields in a Widget subclass are
- // always marked "final".
-
- final String title;
+class HomePage extends StatefulWidget {
+ const HomePage({super.key});
@override
- State<MyHomePage> createState() => _MyHomePageState();
+ State<HomePage> createState() => _HomePageState();
}
-class _MyHomePageState extends State<MyHomePage> {
+class _HomePageState extends State<HomePage> {
StreamSubscription<Position>? _positionStream;
double _speed = 0.0;
double _speedAccuracy = 0.0;
@@ -76,8 +64,10 @@ class _MyHomePageState extends State<MyHomePage> { locationSettings: _locationSettings,
).listen((Position? position) {
if (position != null) {
- _speed = position.speed;
- _speedAccuracy = position.speedAccuracy;
+ setState(() {
+ _speed = position.speed;
+ _speedAccuracy = position.speedAccuracy;
+ });
}
});
}
@@ -90,25 +80,26 @@ class _MyHomePageState extends State<MyHomePage> { @override
Widget build(BuildContext context) {
- // This method is rerun every time setState is called, for instance as done
- // by the _incrementCounter method above.
- //
- // The Flutter framework has been optimized to make rerunning build methods
- // fast, so that you can just rebuild anything that needs updating rather
- // than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
- // TRY THIS: Try changing the color here to a specific color (to
- // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
- // change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
- // Here we take the value from the MyHomePage object that was created by
- // the App.build method, and use it to set our appbar title.
- title: Text(widget.title),
+ title: Text("Speedometer"),
+ actions: [
+ MenuAnchor(
+ builder: (context, controller, _child) => IconButton(
+ icon: Icon(Icons.more_vert),
+ onPressed: () =>
+ controller.isOpen ? controller.close() : controller.open(),
+ tooltip: "Navigation menu",
+ ),
+ menuChildren: [
+ MenuItemButton(child: Text('Settings')),
+ MenuItemButton(child: Text('About')),
+ ],
+ ),
+ ],
),
body: Center(
- // Center is a layout widget. It takes a single child and positions it
- // in the middle of the parent.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
|
