@@ -18,6 +18,7 @@ import 'package:flutter/material.dart';
1818import 'package:flutter/scheduler.dart' ;
1919import 'package:flutter_bloc/flutter_bloc.dart' ;
2020import 'package:go_router/go_router.dart' ;
21+ import 'package:launch_at_startup/launch_at_startup.dart' ;
2122
2223class SettingPage extends StatefulWidget {
2324 static const routePath = '/setting' ;
@@ -33,7 +34,9 @@ class _SettingPageState extends State<SettingPage> {
3334 final helper = sl <Helper >();
3435 final valueNotifierIsEnableScreenshotNotification = ValueNotifier (false );
3536 final valueNotifierAppearanceMode = ValueNotifier (AppearanceMode .light);
37+ final valueNotifierLaunchAtStartup = ValueNotifier (true );
3638 final widgetHelper = WidgetHelper ();
39+ final sharedPreferencesManager = sl <SharedPreferencesManager >();
3740
3841 var hostname = '' ;
3942 late AppearanceBloc appearanceBloc;
@@ -48,6 +51,9 @@ class _SettingPageState extends State<SettingPage> {
4851
4952 @override
5053 void initState () {
54+ launchAtStartup.isEnabled ().then ((value) {
55+ valueNotifierLaunchAtStartup.value = value;
56+ });
5157 appearanceBloc = BlocProvider .of <AppearanceBloc >(context);
5258 final strUserRole = sharedPreferencesManager.getString (SharedPreferencesManager .keyUserRole) ?? '' ;
5359 userRole = strUserRole.fromStringUserRole;
@@ -99,6 +105,8 @@ class _SettingPageState extends State<SettingPage> {
99105 const SizedBox (height: 8 ),
100106 buildWidgetScreenshotNotification (),
101107 const SizedBox (height: 16 ),
108+ buildWidgetLaunchAtStartup (),
109+ const SizedBox (height: 16 ),
102110 buildWidgetSetHostName (),
103111 const SizedBox (height: 16 ),
104112 buildWidgetCheckForUpdate (),
@@ -113,8 +121,56 @@ class _SettingPageState extends State<SettingPage> {
113121 );
114122 }
115123
124+ Widget buildWidgetLaunchAtStartup () {
125+ return Row (
126+ crossAxisAlignment: CrossAxisAlignment .start,
127+ children: [
128+ Expanded (
129+ child: Column (
130+ crossAxisAlignment: CrossAxisAlignment .start,
131+ children: [
132+ Text (
133+ 'launch_at_startup' .tr (),
134+ style: Theme .of (context).textTheme.bodyLarge,
135+ ),
136+ Text (
137+ 'subtitle_launch_at_startup' .tr (),
138+ style: Theme .of (context).textTheme.bodyMedium? .copyWith (
139+ color: Colors .grey,
140+ ),
141+ ),
142+ ],
143+ ),
144+ ),
145+ const SizedBox (width: 16 ),
146+ ValueListenableBuilder (
147+ valueListenable: valueNotifierLaunchAtStartup,
148+ builder: (BuildContext context, bool value, _) {
149+ return Switch .adaptive (
150+ value: value,
151+ onChanged: (newValue) async {
152+ if (newValue) {
153+ await launchAtStartup.enable ();
154+ } else {
155+ await launchAtStartup.disable ();
156+ }
157+ sharedPreferencesManager.putBool (
158+ SharedPreferencesManager .keyIsLaunchAtStartup,
159+ newValue,
160+ );
161+ valueNotifierLaunchAtStartup.value = newValue;
162+ },
163+ activeColor: Theme .of (context).colorScheme.primary,
164+ );
165+ },
166+ ),
167+ ],
168+ );
169+ }
170+
116171 Widget buildWidgetScreenshotNotification () {
117172 return Row (
173+ crossAxisAlignment: CrossAxisAlignment .start,
118174 children: [
119175 Expanded (
120176 child: Column (
0 commit comments