Skip to content

Commit

Permalink
feat: launch at startup toggle and material 3
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Mar 1, 2023
1 parent 7093413 commit 74931bb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/components/ui/top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class TopBar extends StatelessWidget with PreferredSizeWidget {
height: 20,
width: double.infinity,
color: Colors.transparent,
child: ElevatedButtonTheme(
data: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
child: FilledButtonTheme(
data: FilledButtonThemeData(
style: FilledButton.styleFrom(
shape: const CircleBorder(),
minimumSize: const Size(10, 10),
),
Expand All @@ -40,7 +40,7 @@ class TopBar extends StatelessWidget with PreferredSizeWidget {
start: 0,
child: Padding(
padding: const EdgeInsets.only(top: 5.0),
child: ElevatedButton(
child: FilledButton(
onPressed: () => Navigator.of(context).pop(),
child: const Icon(Icons.arrow_back, size: 14),
),
Expand All @@ -51,7 +51,7 @@ class TopBar extends StatelessWidget with PreferredSizeWidget {
end: 0,
child: Padding(
padding: const EdgeInsets.only(top: 5.0),
child: ElevatedButton(
child: FilledButton(
onPressed: () =>
CloseWindowAction().invoke(const CloseWindowIntent()),
child: const Icon(Icons.close, size: 14),
Expand Down
19 changes: 19 additions & 0 deletions lib/hooks/use_force_updater.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/scheduler.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

void Function([dynamic]) useForceUpdater() {
final state = useState(false);
final isMounted = useIsMounted();
return ([_]) async {
if (!isMounted()) return;

// if there's a current frame,
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) {
// wait for the end of that frame.
await SchedulerBinding.instance.endOfFrame;
if (!isMounted()) return;
}

state.value = !state.value;
};
}
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ class _FlemoziState extends State<Flemozi> with WidgetsBindingObserver {
child: MaterialApp(
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: ThemeData.light(),
theme: ThemeData.light(useMaterial3: true),
darkTheme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: SystemTheme.accentColor.accent,
splashFactory: NoSplash.splashFactory,
Expand Down
25 changes: 25 additions & 0 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flemozi/components/ui/top_bar.dart';
import 'package:flemozi/hooks/use_force_updater.dart';
import 'package:flemozi/pages/settings/about.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:launch_at_startup/launch_at_startup.dart';

class Settings extends StatelessWidget {
const Settings({super.key});
Expand All @@ -20,6 +23,28 @@ class Settings extends StatelessWidget {
child: ListView(
padding: const EdgeInsets.all(20),
children: [
HookBuilder(
builder: (context) {
final update = useForceUpdater();
final snapshot = useFuture(launchAtStartup.isEnabled());
return SwitchListTile(
secondary: const Icon(Icons.power_settings_new),
title: const Text('Launch at startup'),
value: snapshot.data ?? false,
onChanged: !snapshot.hasData
? null
: (value) async {
if (value) {
await launchAtStartup.enable();
} else {
await launchAtStartup.disable();
}
update();
},
);
},
),
const SizedBox(height: 5),
ListTile(
title: const Text('About'),
leading: const Icon(Icons.info),
Expand Down

0 comments on commit 74931bb

Please sign in to comment.