ModernMemoires/lib/views/settings_page/widgets/settings_selection_widget.dart

75 lines
1.8 KiB
Dart
Raw Normal View History

2024-01-09 12:34:44 +01:00
import 'package:flutter/foundation.dart';
2023-12-17 23:00:31 +01:00
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class SettingsSection extends StatelessWidget {
final String title;
final List<SettingsItem> items;
2024-01-09 12:34:44 +01:00
const SettingsSection({Key? key, required this.title, required this.items}) : super(key: key);
2023-12-17 23:00:31 +01:00
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
2024-01-09 12:34:44 +01:00
padding: const EdgeInsets.all(8.0),
2023-12-17 23:00:31 +01:00
child: Text(
title,
2024-01-09 12:34:44 +01:00
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),
2023-12-17 23:00:31 +01:00
),
),
...items.map((item) => _buildItem(item)).toList(),
],
);
}
Widget _buildItem(SettingsItem item) {
return ExpansionTile(
title: Text(item.title),
children: [
ListTile(
title: Text(item.detail),
trailing: item.url != null
? GestureDetector(
child: Text(
item.trailingText ?? "",
2024-01-09 12:34:44 +01:00
style: const TextStyle(color: Colors.grey),
2023-12-17 23:00:31 +01:00
),
2024-01-09 12:34:44 +01:00
onTap: () => _launchURL(Uri.parse(item.url!)),
2023-12-17 23:00:31 +01:00
)
: null,
onTap: item.onTap,
),
],
);
}
2024-01-09 12:34:44 +01:00
void _launchURL(Uri url) async {
if (await canLaunchUrl(url)) {
await launchUrl(url);
2023-12-17 23:00:31 +01:00
} else {
2024-01-09 12:34:44 +01:00
if (kDebugMode) {
print("Could not launch $url");
}
2023-12-17 23:00:31 +01:00
}
}
}
class SettingsItem {
final String title;
final String detail;
final String? trailingText;
final String? url;
final VoidCallback? onTap;
SettingsItem({
required this.title,
this.detail = '',
this.trailingText,
this.url,
this.onTap,
});
}