hrt/lib/main.dart

79 lines
2.2 KiB
Dart
Raw Permalink Normal View History

2023-09-23 20:01:51 +00:00
import 'package:dynamic_color/dynamic_color.dart';
2023-09-23 19:50:29 +00:00
import 'package:flutter/material.dart';
2023-10-05 17:33:47 +00:00
import 'package:hrt/notification.dart';
2023-10-06 12:18:35 +00:00
import 'package:hrt/tasks.dart';
2023-10-05 17:33:47 +00:00
import 'package:permission_handler/permission_handler.dart';
2023-09-23 19:50:29 +00:00
void main() {
2023-09-23 20:01:51 +00:00
runApp(const App());
2023-09-23 19:50:29 +00:00
}
2023-09-23 20:01:51 +00:00
class App extends StatelessWidget {
const App({super.key});
2023-09-23 19:50:29 +00:00
@override
Widget build(BuildContext context) {
2023-10-06 12:18:35 +00:00
setupBackgroundTasks();
2023-09-23 20:01:51 +00:00
return DynamicColorBuilder(
builder: ((lightDynamic, darkDynamic) => MaterialApp(
title: "HRT",
theme: ThemeData(
brightness: Brightness.light,
useMaterial3: true,
colorScheme: lightDynamic,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
colorScheme: darkDynamic,
),
themeMode: ThemeMode.system,
home: const HomePage(title: "HRT"))),
2023-09-23 19:50:29 +00:00
);
}
}
2023-09-23 20:01:51 +00:00
class HomePage extends StatefulWidget {
const HomePage({super.key, required this.title});
2023-09-23 19:50:29 +00:00
// 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
2023-09-23 20:01:51 +00:00
State<HomePage> createState() => _HomePageState();
2023-09-23 19:50:29 +00:00
}
2023-09-23 20:01:51 +00:00
class _HomePageState extends State<HomePage> {
2023-09-23 19:50:29 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
2023-10-05 17:33:47 +00:00
child: TextButton(
child: const Text("Test notification"),
onPressed: () async {
await Permission.notification.isDenied.then((value) async {
if (value) {
await Permission.notification.request();
}
});
scheduleNotification();
2023-10-05 17:33:47 +00:00
},
2023-09-23 19:50:29 +00:00
),
),
);
}
}