74 lines
1.7 KiB
Dart
74 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class SettingsSection extends StatelessWidget {
|
|
final String title;
|
|
final List<SettingsItem> items;
|
|
|
|
SettingsSection({Key? key, required this.title, required this.items})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.all(8.0),
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black),
|
|
),
|
|
),
|
|
...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 ?? "",
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
onTap: () => _launchURL(item.url!),
|
|
)
|
|
: null,
|
|
onTap: item.onTap,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _launchURL(String url) async {
|
|
if (await canLaunch(url)) {
|
|
await launch(url);
|
|
} else {
|
|
print("Could not launch $url");
|
|
}
|
|
}
|
|
}
|
|
|
|
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,
|
|
});
|
|
}
|