ModernMemoires/lib/views/settings_page/settings_page.dart

172 lines
6.2 KiB
Dart
Raw Normal View History

2023-12-17 23:00:31 +01:00
import 'package:flutter/material.dart';
2024-01-01 18:31:10 +01:00
import 'package:go_router/go_router.dart';
2024-01-13 17:07:11 +01:00
import 'package:url_launcher/url_launcher.dart';
2023-12-17 23:00:31 +01:00
2024-01-08 19:34:48 +01:00
import '../../utils/definitions/style_guide.dart';
2024-01-09 12:34:44 +01:00
import '../../utils/logic/preferences_service.dart';
import '../../utils/widgets/custom_bottom_navigation_bar.dart';
2024-01-13 17:07:11 +01:00
import '../../utils/widgets/no_Glow_scroll_behavior.dart';
2024-01-09 12:34:44 +01:00
import 'widgets/custom_divider_widget.dart';
import 'widgets/set_pin_popup_widget.dart';
import 'widgets/text_switch_container_widget.dart';
2023-12-17 23:00:31 +01:00
2024-01-01 19:52:42 +01:00
class SettingsPage extends StatefulWidget {
2024-01-09 12:34:44 +01:00
const SettingsPage({super.key});
2024-01-01 19:52:42 +01:00
@override
2024-01-09 12:34:44 +01:00
State<SettingsPage> createState() => _SettingsPage();
2024-01-01 19:52:42 +01:00
}
2024-01-09 12:34:44 +01:00
class _SettingsPage extends State<SettingsPage> {
2024-01-01 19:52:42 +01:00
bool isPinEnabled = false; // Default to false
@override
void initState() {
super.initState();
_loadPinEnabledState();
}
void _loadPinEnabledState() async {
isPinEnabled = await PreferencesService().isPinEnabled();
setState(() {});
}
2024-01-13 17:07:11 +01:00
Future<void> _launchUrl(Uri url) async {
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
}
2023-12-17 23:00:31 +01:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-01-08 19:34:48 +01:00
backgroundColor: AppStyle.backgroundColor,
2024-01-01 18:31:10 +01:00
body: Container(
2024-01-09 12:34:44 +01:00
padding: const EdgeInsets.only(bottom: 0),
2024-01-01 18:31:10 +01:00
margin: const EdgeInsets.fromLTRB(30, 30, 30, 0),
2024-01-13 17:07:11 +01:00
child: ScrollConfiguration(
behavior: NoGlowScrollBehavior(),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(
height: 100,
2024-01-01 18:31:10 +01:00
),
2024-01-13 17:07:11 +01:00
// Settings section
Container(
margin: const EdgeInsets.only(bottom: 10),
2024-01-01 18:31:10 +01:00
alignment: Alignment.topLeft,
2024-01-13 17:07:11 +01:00
child: const Text('settings', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)),
),
TextSwitchContainer(
leftText: "change color",
onTap: () => context.go("/color"),
),
const CustomDivider(),
FutureBuilder<bool>(
future: PreferencesService().isPinEnabled(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator(); // or some other placeholder
}
bool pinEnabled = snapshot.data ?? false; // Default to false if null
return TextSwitchContainer(
leftText: "pin",
hasSwitch: true,
onTap: () => {showSetPinPopup(context)},
onSwitchToggle: (value) {
if (value) {
PreferencesService().enablePin();
} else {
PreferencesService().disablePin();
}
// Consider updating the state here or using other state management
},
switchDefaultValue: pinEnabled,
);
},
),
const CustomDivider(),
TextSwitchContainer(
leftText: "your data",
onTap: () => {},
),
// Community section
Padding(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 10),
child: Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(bottom: 10),
child: const Text('community', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)),
),
),
TextSwitchContainer(
leftText: "join our discord",
rightText: "fulfilled",
onTap: () async => {await _launchUrl(Uri.parse("https://discord.gg/qaVjyqHW5s"))}, // Implement your logic
),
const CustomDivider(),
TextSwitchContainer(
leftText: "our instagram",
rightText: "@get.fulfilled",
onTap: () async => {await _launchUrl(Uri.parse("http://instagram.com/get.fulfilled"))}, // Implement your logic
),
const CustomDivider(),
TextSwitchContainer(
leftText: "share fulfilled with your loved ones",
onTap: () => {},
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 10),
child: Container(
alignment: Alignment.topLeft,
child: const Text('humans behind fulfilled', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)),
),
),
TextSwitchContainer(
leftText: "about us",
onTap: () => {context.go("/about")},
),
const CustomDivider(),
TextSwitchContainer(
leftText: "support us",
onTap: () => {},
),
const CustomDivider(),
TextSwitchContainer(
leftText: "give feedback",
onTap: () => {},
),
//
2024-01-13 17:07:46 +01:00
const SizedBox(
height: 30,
2024-01-13 17:07:11 +01:00
),
GestureDetector(
child: const Text('imprint & privacy policy', style: TextStyle(color: Colors.grey, fontSize: 15)),
onTap: () => {context.go("/imprint")}, // Implement your logic
2024-01-01 18:31:10 +01:00
),
2024-01-13 17:07:11 +01:00
const SizedBox(
height: 150,
)
],
),
2024-01-01 18:31:10 +01:00
),
),
2023-12-17 23:00:31 +01:00
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
2024-01-09 12:34:44 +01:00
floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 2),
2024-01-01 18:31:10 +01:00
);
}
void showSetPinPopup(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
2024-01-09 12:34:44 +01:00
return const SetPinPopup();
2024-01-01 18:31:10 +01:00
},
2023-12-17 23:00:31 +01:00
);
}
2023-12-25 14:10:31 +01:00
}