96 lines
3.6 KiB
Dart
96 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
|
|
import '../main.dart';
|
|
import 'login_screen.dart';
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('设置')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('服务器', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
Text('地址: ${settings.serverUrl ?? "未设置"}',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: colors.onSurfaceVariant)),
|
|
Text('令牌: ${settings.token != null ? "已配置" : "未设置"}',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: colors.onSurfaceVariant)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('上传模式', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
SwitchListTile(
|
|
title: const Text('自动上传'),
|
|
subtitle: Text(
|
|
settings.autoUpload
|
|
? '后台服务运行中,自动上传新短信'
|
|
: '自动上传新收到的短信',
|
|
style: TextStyle(color: settings.autoUpload ? colors.primary : null),
|
|
),
|
|
value: settings.autoUpload,
|
|
onChanged: (v) {
|
|
settings.setAutoUpload(v);
|
|
if (!v) {
|
|
FlutterForegroundTask.stopService();
|
|
}
|
|
setState(() {});
|
|
},
|
|
contentPadding: EdgeInsets.zero,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () {
|
|
FlutterForegroundTask.stopService();
|
|
settings.setToken('');
|
|
settings.setAutoUpload(false);
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
|
(_) => false,
|
|
);
|
|
},
|
|
icon: const Icon(Icons.logout),
|
|
label: const Text('断开连接'),
|
|
style: OutlinedButton.styleFrom(foregroundColor: colors.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|