Skip to content

Commit 0ab0313

Browse files
committed
Buat UI dan fitur pengaturan launch at startup di halaman setting_page.dart
1 parent c08a701 commit 0ab0313

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/core/util/shared_preferences_manager.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SharedPreferencesManager {
1616
static const keyIsEnableScreenshotNotification = 'is_enable_screenshot_notification';
1717
static const keyAppearanceMode = 'appearance_mode';
1818
static const keyBaseFilePathScreenshot = 'base_file_path_screenshot';
19+
static const keyIsLaunchAtStartup = 'is_launch_at_startup';
1920

2021
SharedPreferencesManager();
2122

lib/feature/presentation/page/setting/setting_page.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:flutter/material.dart';
1818
import 'package:flutter/scheduler.dart';
1919
import 'package:flutter_bloc/flutter_bloc.dart';
2020
import 'package:go_router/go_router.dart';
21+
import 'package:launch_at_startup/launch_at_startup.dart';
2122

2223
class 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

Comments
 (0)