working time

This commit is contained in:
Henry Hiles 2026-04-18 11:14:13 -04:00
commit 877b6cc393
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
11 changed files with 833 additions and 144 deletions

View file

@ -0,0 +1,11 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
class TimeController extends StreamNotifier<DateTime> {
@override
Stream<DateTime> build() =>
Stream.periodic(Duration(seconds: 1), (_) => DateTime.now());
static final provider = StreamNotifierProvider<TimeController, DateTime>(
TimeController.new,
);
}

View file

@ -0,0 +1,15 @@
import "package:flight/widgets/loading.dart";
import "package:flutter/material.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";
extension BetterWhen<T> on AsyncValue<T> {
Widget betterWhen({
required Widget Function(T value) data,
Widget Function() loading = Loading.new,
}) => when(
data: data,
error: (error, stackTrace) =>
Text("$error: $stackTrace", style: TextStyle(color: Colors.red)),
loading: loading,
);
}

View file

@ -0,0 +1,13 @@
import "package:flutter/material.dart";
extension SchemeToTheme on ColorScheme {
ThemeData get theme => ThemeData.from(colorScheme: this).copyWith(
textTheme: ThemeData(
fontFamilyFallback: ["sans", "emoji"],
brightness: brightness,
).textTheme,
inputDecorationTheme: const InputDecorationTheme(
border: OutlineInputBorder(),
),
);
}

View file

@ -1,4 +1,9 @@
import 'package:dynamic_system_colors/dynamic_system_colors.dart';
import 'package:flight/helpers/extensions/scheme_to_theme.dart';
import 'package:flight/widgets/bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wayland_layer_shell/types.dart';
import 'package:wayland_layer_shell/wayland_layer_shell.dart';
void main() async {
@ -9,105 +14,30 @@ void main() async {
runApp(const MaterialApp(home: Center(child: Text('Not supported'))));
return;
}
await waylandLayerShellPlugin.setAnchor(ShellEdge.edgeLeft, true);
await waylandLayerShellPlugin.setAnchor(ShellEdge.edgeRight, true);
await waylandLayerShellPlugin.setAnchor(ShellEdge.edgeBottom, true);
await waylandLayerShellPlugin.setExclusiveZone(48);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
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;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@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),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
children: [
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
runApp(
ProviderScope(
child: DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) => MaterialApp(
debugShowCheckedModeBanner: false,
// Use indigo to work around bugs in theme generation
theme:
(lightDynamic ?? ColorScheme.fromSeed(seedColor: Colors.indigo))
.theme,
darkTheme:
(darkDynamic ??
ColorScheme.fromSeed(
seedColor: Colors.indigo,
brightness: Brightness.dark,
))
.theme,
home: Scaffold(body: Bar()),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
),
);
}

51
lib/widgets/bar.dart Normal file
View file

@ -0,0 +1,51 @@
import 'package:flight/controllers/time_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
class Bar extends ConsumerWidget {
const Bar({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) => Center(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
spacing: 4,
children: [
Icon(Icons.circle),
Icon(Icons.circle_outlined),
Icon(Icons.circle_outlined),
],
),
Row(
children: [
Text(
DateFormat.Hm().format(
ref
.watch(TimeController.provider)
.when(
data: (time) => time,
loading: DateTime.now,
error: (_, _) => DateTime.now(),
),
),
),
],
),
Row(
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.wifi)),
IconButton(onPressed: () {}, icon: Icon(Icons.bluetooth)),
IconButton(onPressed: () {}, icon: Icon(Icons.volume_off)),
],
),
],
),
),
);
}

14
lib/widgets/loading.dart Normal file
View file

@ -0,0 +1,14 @@
import "package:flutter/material.dart";
class Loading extends StatelessWidget {
final double? height;
const Loading({this.height, super.key});
@override
Widget build(BuildContext context) => Center(
child: Padding(
padding: EdgeInsets.all(16),
child: SizedBox(height: height, child: CircularProgressIndicator()),
),
);
}