-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gui] show rudimentary instance info
- Loading branch information
1 parent
f8dea3a
commit 73905e9
Showing
2 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import 'package:desktop_gui/grpc_client.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
void main() { | ||
runApp(const MaterialApp(home: MyHomePage())); | ||
runApp(const ProviderScope(child: MaterialApp(home: MyHomePage()))); | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
class MyHomePage extends ConsumerWidget { | ||
const MyHomePage({super.key}); | ||
|
||
@override | ||
State<MyHomePage> createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
int _counter = 0; | ||
Widget _buildInfosColumn(Iterable<VmInfo> infos) { | ||
return Column( | ||
children: infos | ||
.map((info) => Text('${info.name} ${info.instanceStatus.status}')) | ||
.toList(), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center(child: Text('$_counter')), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () => setState(() => _counter++), | ||
), | ||
); | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final body = ref.watch(vmInfosStreamProvider).when( | ||
data: _buildInfosColumn, | ||
error: (error, _) => Text('$error'), | ||
loading: () => const Text('Loading...'), | ||
); | ||
return Scaffold(body: body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters