init
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
|
||||
import '../main.dart';
|
||||
import 'login_screen.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
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('Settings')),
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -22,11 +28,11 @@ class SettingsScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Server', style: Theme.of(context).textTheme.titleMedium),
|
||||
Text('服务器', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
Text('URL: ${settings.serverUrl ?? "Not set"}',
|
||||
Text('地址: ${settings.serverUrl ?? "未设置"}',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: colors.onSurfaceVariant)),
|
||||
Text('Token: ${settings.token != null ? "Configured" : "Missing"}',
|
||||
Text('令牌: ${settings.token != null ? "已配置" : "未设置"}',
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(color: colors.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
@@ -39,13 +45,24 @@ class SettingsScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Upload Mode', style: Theme.of(context).textTheme.titleMedium),
|
||||
Text('上传模式', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
title: const Text('Auto Upload'),
|
||||
subtitle: const Text('Automatically upload new incoming SMS'),
|
||||
title: const Text('自动上传'),
|
||||
subtitle: Text(
|
||||
settings.autoUpload
|
||||
? '后台服务运行中,自动上传新短信'
|
||||
: '自动上传新收到的短信',
|
||||
style: TextStyle(color: settings.autoUpload ? colors.primary : null),
|
||||
),
|
||||
value: settings.autoUpload,
|
||||
onChanged: (v) => settings.setAutoUpload(v),
|
||||
onChanged: (v) {
|
||||
settings.setAutoUpload(v);
|
||||
if (!v) {
|
||||
FlutterForegroundTask.stopService();
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
],
|
||||
@@ -57,14 +74,16 @@ class SettingsScreen extends StatelessWidget {
|
||||
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('Logout'),
|
||||
label: const Text('断开连接'),
|
||||
style: OutlinedButton.styleFrom(foregroundColor: colors.error),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user