ponshu-room-lite/lib/widgets/settings/other_settings_section.dart

95 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lucide_icons/lucide_icons.dart';
import 'package:package_info_plus/package_info_plus.dart';
import '../../providers/theme_provider.dart';
class OtherSettingsSection extends ConsumerStatefulWidget {
final bool showBusinessMode;
final String title;
const OtherSettingsSection({
super.key,
this.showBusinessMode = true,
this.title = 'データ・その他',
});
@override
ConsumerState<OtherSettingsSection> createState() => _OtherSettingsSectionState();
}
class _OtherSettingsSectionState extends ConsumerState<OtherSettingsSection> {
String _appVersion = 'Loading...';
@override
void initState() {
super.initState();
_loadAppVersion();
}
Future<void> _loadAppVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
if (mounted) {
setState(() {
_appVersion = 'v${packageInfo.version}+${packageInfo.buildNumber} (Lite)';
});
}
}
@override
Widget build(BuildContext context) {
final userProfile = ref.watch(userProfileProvider);
final isDark = Theme.of(context).brightness == Brightness.dark;
return Column(
children: [
_buildSectionHeader(context, widget.title, LucideIcons.database),
Card(
child: Column(
children: [
if (widget.showBusinessMode) ...[
ListTile(
leading: Icon(LucideIcons.store, color: isDark ? Colors.orange[300] : Colors.orange),
title: const Text('飲食店モード (Beta)'),
subtitle: const Text('お品書き作成機能など'),
trailing: Switch(
value: userProfile.isBusinessMode,
onChanged: (val) => ref.read(userProfileProvider.notifier).toggleBusinessMode(),
activeThumbColor: Colors.orange,
),
),
const Divider(height: 1),
],
ListTile(
leading: Icon(LucideIcons.info, color: isDark ? Colors.grey[400] : null),
title: const Text('アプリバージョン'),
subtitle: Text(_appVersion),
),
],
),
),
],
);
}
Widget _buildSectionHeader(BuildContext context, String title, IconData icon) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4),
child: Row(
children: [
Icon(icon, size: 20, color: isDark ? Colors.orange[300] : Theme.of(context).primaryColor),
const SizedBox(width: 8),
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: isDark ? Colors.grey[300] : Theme.of(context).primaryColor,
),
),
],
),
);
}
}