2023-05-05 06:45:00 -04:00
|
|
|
import 'package:contacts_plus_plus/client_holder.dart';
|
2023-05-03 11:51:18 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-06 05:18:00 -04:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2023-05-03 15:55:34 -04:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2023-05-03 11:51:18 -04:00
|
|
|
|
|
|
|
class SettingsPage extends StatelessWidget {
|
|
|
|
const SettingsPage({super.key});
|
2023-05-03 17:24:27 -04:00
|
|
|
|
2023-05-03 11:51:18 -04:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-03 17:24:27 -04:00
|
|
|
final sClient = ClientHolder.of(context).settingsClient;
|
2023-05-03 11:51:18 -04:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
),
|
|
|
|
title: const Text("Settings"),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
2023-05-03 17:24:27 -04:00
|
|
|
const ListSectionHeader(name: "Notifications"),
|
|
|
|
BooleanSettingsTile(
|
2023-05-04 07:13:24 -04:00
|
|
|
title: "Enable Notifications",
|
|
|
|
initialState: !sClient.currentSettings.notificationsDenied.valueOrDefault,
|
|
|
|
onChanged: (value) async => await sClient.changeSettings(sClient.currentSettings.copyWith(notificationsDenied: !value)),
|
2023-05-03 17:24:27 -04:00
|
|
|
),
|
|
|
|
const ListSectionHeader(name: "Other"),
|
2023-05-03 11:51:18 -04:00
|
|
|
ListTile(
|
2023-05-03 12:16:40 -04:00
|
|
|
trailing: const Icon(Icons.logout),
|
2023-05-03 11:51:18 -04:00
|
|
|
title: const Text("Sign out"),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
AlertDialog(
|
|
|
|
title: Text("Are you sure you want to sign out?", style: Theme
|
|
|
|
.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleLarge,),
|
|
|
|
actions: [
|
|
|
|
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("No")),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
2023-05-03 15:55:34 -04:00
|
|
|
await ClientHolder.of(context).apiClient.logout(context);
|
2023-05-03 11:51:18 -04:00
|
|
|
},
|
|
|
|
child: const Text("Yes"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-05-03 15:55:34 -04:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
trailing: const Icon(Icons.info_outline),
|
|
|
|
title: const Text("About Contacts++"),
|
2023-05-06 05:18:00 -04:00
|
|
|
onTap: () async {
|
2023-05-03 15:55:34 -04:00
|
|
|
showAboutDialog(
|
|
|
|
context: context,
|
2023-05-06 05:18:00 -04:00
|
|
|
applicationVersion: (await PackageInfo.fromPlatform()).version,
|
2023-05-03 15:55:34 -04:00
|
|
|
applicationIcon: InkWell(
|
|
|
|
onTap: () async {
|
|
|
|
if (!await launchUrl(Uri.parse("https://github.com/Nutcake/contacts-plus-plus"), mode: LaunchMode.externalApplication)) {
|
|
|
|
if (context.mounted) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Failed to open link.")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
constraints: const BoxConstraints(maxWidth: 64),
|
|
|
|
child: Image.asset("assets/images/logo512.png"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
applicationLegalese: "Created by Nutcake with love <3",
|
|
|
|
);
|
|
|
|
},
|
2023-05-03 11:51:18 -04:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-05-03 17:24:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class ListSectionHeader extends StatelessWidget {
|
|
|
|
const ListSectionHeader({required this.name, super.key});
|
|
|
|
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(name, style: theme.textTheme.labelSmall?.copyWith(color: theme.colorScheme.onSurfaceVariant)),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
color: Colors.white12,
|
|
|
|
height: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BooleanSettingsTile extends StatefulWidget {
|
|
|
|
const BooleanSettingsTile({required this.title, required this.initialState, required this.onChanged, super.key});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
final bool initialState;
|
|
|
|
final Function(bool) onChanged;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _BooleanSettingsTileState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BooleanSettingsTileState extends State<BooleanSettingsTile> {
|
|
|
|
late bool state = widget.initialState;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
trailing: Switch(
|
|
|
|
onChanged: (value) async {
|
|
|
|
await widget.onChanged(value);
|
|
|
|
setState(() {
|
|
|
|
state = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
value: state,
|
|
|
|
),
|
|
|
|
title: Text(widget.title),
|
|
|
|
onTap: () async {
|
|
|
|
await widget.onChanged(!state);
|
|
|
|
setState(() {
|
|
|
|
state = !state;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:51:18 -04:00
|
|
|
}
|