Improve settings and playback controls

This commit is contained in:
2026-04-01 18:04:37 +08:00
parent 2d0acad161
commit f97195d640
9 changed files with 488 additions and 130 deletions

View File

@@ -1,11 +1,15 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/settings_provider.dart';
import '../providers/auth_provider.dart';
import '../providers/settings_provider.dart';
import '../services/api_service.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@override
_SettingsPageState createState() => _SettingsPageState();
}
@@ -28,7 +32,9 @@ class _SettingsPageState extends State<SettingsPage> {
@override
void initState() {
super.initState();
_urlController = TextEditingController(text: context.read<SettingsProvider>().baseUrl);
_urlController = TextEditingController(
text: context.read<SettingsProvider>().baseUrl,
);
}
@override
@@ -44,23 +50,41 @@ class _SettingsPageState extends State<SettingsPage> {
final auth = context.read<AuthProvider>();
final api = ApiService(settings, auth.token);
if (_oldPasswordController.text.isEmpty || _newPasswordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Please fill in both password fields")));
if (_oldPasswordController.text.isEmpty ||
_newPasswordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Please fill in both password fields")),
);
return;
}
try {
final resp = await api.changePassword(_oldPasswordController.text, _newPasswordController.text);
final resp = await api.changePassword(
_oldPasswordController.text,
_newPasswordController.text,
);
if (!mounted) {
return;
}
final data = jsonDecode(resp.body);
if (resp.statusCode == 200) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Password updated successfully")));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Password updated successfully")),
);
_oldPasswordController.clear();
_newPasswordController.clear();
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Error: ${data['error']}")));
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text("Error: ${data['error']}")));
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Failed to connect to server")));
if (!mounted) {
return;
}
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text("Failed to connect to server")));
}
}
@@ -68,6 +92,7 @@ class _SettingsPageState extends State<SettingsPage> {
Widget build(BuildContext context) {
final auth = context.watch<AuthProvider>();
final settings = context.watch<SettingsProvider>();
final isAuthenticated = auth.isAuthenticated;
return Scaffold(
appBar: AppBar(
@@ -79,49 +104,94 @@ class _SettingsPageState extends State<SettingsPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// User Profile Section
_buildProfileSection(auth),
SizedBox(height: 32),
// Network Configuration
if (isAuthenticated) ...[
_buildProfileSection(auth),
const SizedBox(height: 32),
],
_buildSectionTitle("Network Configuration"),
SizedBox(height: 16),
const SizedBox(height: 16),
TextField(
controller: _urlController,
decoration: InputDecoration(
labelText: "Backend Server URL",
hintText: "http://127.0.0.1:8080",
prefixIcon: Icon(Icons.lan),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
SizedBox(height: 12),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () {
context.read<SettingsProvider>().setBaseUrl(_urlController.text);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Server URL Updated"), behavior: SnackBarBehavior.floating));
context.read<SettingsProvider>().setBaseUrl(
_urlController.text,
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Server URL Updated"),
behavior: SnackBarBehavior.floating,
),
);
},
icon: Icon(Icons.save),
label: Text("Save Network Settings"),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
foregroundColor: Theme.of(context).colorScheme.onPrimaryContainer,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
backgroundColor: Theme.of(
context,
).colorScheme.primaryContainer,
foregroundColor: Theme.of(
context,
).colorScheme.onPrimaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
SizedBox(height: 32),
const SizedBox(height: 32),
// Theme Color Section
_buildSectionTitle("Theme Customization"),
SizedBox(height: 16),
const SizedBox(height: 16),
Text(
"Appearance Mode",
style: Theme.of(context).textTheme.labelLarge,
),
const SizedBox(height: 12),
SegmentedButton<ThemeMode>(
segments: const [
ButtonSegment<ThemeMode>(
value: ThemeMode.system,
label: Text("System"),
icon: Icon(Icons.brightness_auto),
),
ButtonSegment<ThemeMode>(
value: ThemeMode.light,
label: Text("Light"),
icon: Icon(Icons.light_mode),
),
ButtonSegment<ThemeMode>(
value: ThemeMode.dark,
label: Text("Dark"),
icon: Icon(Icons.dark_mode),
),
],
selected: {settings.themeMode},
onSelectionChanged: (selection) {
settings.setThemeMode(selection.first);
},
),
const SizedBox(height: 20),
Text("Accent Color", style: Theme.of(context).textTheme.labelLarge),
const SizedBox(height: 12),
Wrap(
spacing: 12,
runSpacing: 12,
children: _availableColors.map((color) {
bool isSelected = settings.themeColor.value == color.value;
final isSelected =
settings.themeColor.toARGB32() == color.toARGB32();
return GestureDetector(
onTap: () => settings.setThemeColor(color),
child: Container(
@@ -130,57 +200,86 @@ class _SettingsPageState extends State<SettingsPage> {
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
border: isSelected ? Border.all(color: Theme.of(context).colorScheme.onSurface, width: 3) : null,
border: isSelected
? Border.all(
color: Theme.of(context).colorScheme.onSurface,
width: 3,
)
: null,
boxShadow: [
BoxShadow(color: Colors.black26, blurRadius: 4, offset: Offset(0, 2)),
BoxShadow(
color: Colors.black26,
blurRadius: 4,
offset: Offset(0, 2),
),
],
),
child: isSelected ? Icon(Icons.check, color: Colors.white) : null,
child: isSelected
? Icon(Icons.check, color: Colors.white)
: null,
),
);
}).toList(),
),
SizedBox(height: 32),
// Security Section
_buildSectionTitle("Security"),
SizedBox(height: 16),
TextField(
controller: _oldPasswordController,
obscureText: true,
decoration: InputDecoration(
labelText: "Old Password",
prefixIcon: Icon(Icons.lock_outline),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
),
SizedBox(height: 12),
TextField(
controller: _newPasswordController,
obscureText: true,
decoration: InputDecoration(
labelText: "New Password",
prefixIcon: Icon(Icons.lock_reset),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
),
SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _handleChangePassword,
icon: Icon(Icons.update),
label: Text("Change Password"),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
if (isAuthenticated) ...[
const SizedBox(height: 32),
_buildSectionTitle("Security"),
const SizedBox(height: 16),
TextField(
controller: _oldPasswordController,
obscureText: true,
decoration: InputDecoration(
labelText: "Old Password",
prefixIcon: const Icon(Icons.lock_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
SizedBox(height: 40),
const SizedBox(height: 12),
TextField(
controller: _newPasswordController,
obscureText: true,
decoration: InputDecoration(
labelText: "New Password",
prefixIcon: const Icon(Icons.lock_reset),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _handleChangePassword,
icon: const Icon(Icons.update),
label: const Text("Change Password"),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: FilledButton.tonalIcon(
onPressed: auth.logout,
icon: const Icon(Icons.logout),
label: const Text("Logout"),
style: FilledButton.styleFrom(
foregroundColor: Colors.redAccent,
padding: const EdgeInsets.symmetric(vertical: 14),
),
),
),
],
const SizedBox(height: 40),
// About Section
Divider(),
SizedBox(height: 20),
const Divider(),
const SizedBox(height: 20),
Center(
child: Column(
children: [
@@ -191,18 +290,39 @@ class _SettingsPageState extends State<SettingsPage> {
color: settings.themeColor,
borderRadius: BorderRadius.circular(12),
),
child: Center(child: Text("H", style: TextStyle(color: Colors.white, fontSize: 32, fontWeight: FontWeight.bold))),
child: Center(
child: Text(
"H",
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(height: 12),
Text("Hightube", style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
Text("Version: 1.0.0-beta3.5", style: TextStyle(color: Colors.grey)),
Text("Author: Highground-Soft & Minimax", style: TextStyle(color: Colors.grey)),
Text(
"Hightube",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
Text(
"Version: 1.0.0-beta3.5",
style: TextStyle(color: Colors.grey),
),
Text(
"Author: Highground-Soft & Minimax",
style: TextStyle(color: Colors.grey),
),
SizedBox(height: 20),
Text("© 2026 Hightube Project", style: TextStyle(fontSize: 12, color: Colors.grey)),
Text(
"© 2026 Hightube Project",
style: TextStyle(fontSize: 12, color: Colors.grey),
),
],
),
),
SizedBox(height: 40),
const SizedBox(height: 40),
],
),
),
@@ -221,9 +341,9 @@ class _SettingsPageState extends State<SettingsPage> {
Widget _buildProfileSection(AuthProvider auth) {
return Container(
padding: EdgeInsets.all(20),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
),
child: Row(
@@ -233,10 +353,14 @@ class _SettingsPageState extends State<SettingsPage> {
backgroundColor: Theme.of(context).colorScheme.primary,
child: Text(
(auth.username ?? "U")[0].toUpperCase(),
style: TextStyle(fontSize: 32, color: Colors.white, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 32,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(width: 20),
const SizedBox(width: 20),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -247,16 +371,13 @@ class _SettingsPageState extends State<SettingsPage> {
),
Text(
"Self-hosted Streamer",
style: TextStyle(color: Theme.of(context).colorScheme.outline),
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
),
),
],
),
),
IconButton(
onPressed: () => auth.logout(),
icon: Icon(Icons.logout, color: Colors.redAccent),
tooltip: "Logout",
),
],
),
);