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

@@ -8,6 +8,8 @@ import 'register_page.dart';
import 'settings_page.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
_LoginPageState createState() => _LoginPageState();
}
@@ -19,7 +21,9 @@ class _LoginPageState extends State<LoginPage> {
void _handleLogin() async {
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Please fill in all fields")));
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text("Please fill in all fields")));
return;
}
@@ -29,16 +33,29 @@ class _LoginPageState extends State<LoginPage> {
final api = ApiService(settings, null);
try {
final response = await api.login(_usernameController.text, _passwordController.text);
final response = await api.login(
_usernameController.text,
_passwordController.text,
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
await auth.login(data['token'], data['username']);
} else {
if (!mounted) {
return;
}
final error = jsonDecode(response.body)['error'] ?? "Login Failed";
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error)));
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(error)));
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Network Error: Could not connect to server")));
if (!mounted) {
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Network Error: Could not connect to server")),
);
} finally {
if (mounted) setState(() => _isLoading = false);
}
@@ -51,7 +68,10 @@ class _LoginPageState extends State<LoginPage> {
actions: [
IconButton(
icon: Icon(Icons.settings),
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => SettingsPage())),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const SettingsPage()),
),
),
],
),
@@ -64,7 +84,11 @@ class _LoginPageState extends State<LoginPage> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Logo & Name
Icon(Icons.flutter_dash, size: 80, color: Theme.of(context).colorScheme.primary),
Icon(
Icons.flutter_dash,
size: 80,
color: Theme.of(context).colorScheme.primary,
),
SizedBox(height: 16),
Text(
"HIGHTUBE",
@@ -75,16 +99,21 @@ class _LoginPageState extends State<LoginPage> {
color: Theme.of(context).colorScheme.primary,
),
),
Text("Open Source Live Platform", style: TextStyle(color: Colors.grey)),
Text(
"Open Source Live Platform",
style: TextStyle(color: Colors.grey),
),
SizedBox(height: 48),
// Fields
TextField(
controller: _usernameController,
decoration: InputDecoration(
labelText: "Username",
prefixIcon: Icon(Icons.person),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
SizedBox(height: 16),
@@ -94,11 +123,13 @@ class _LoginPageState extends State<LoginPage> {
decoration: InputDecoration(
labelText: "Password",
prefixIcon: Icon(Icons.lock),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
SizedBox(height: 32),
// Login Button
SizedBox(
width: double.infinity,
@@ -106,16 +137,26 @@ class _LoginPageState extends State<LoginPage> {
child: ElevatedButton(
onPressed: _isLoading ? null : _handleLogin,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: _isLoading ? CircularProgressIndicator() : Text("LOGIN", style: TextStyle(fontWeight: FontWeight.bold)),
child: _isLoading
? CircularProgressIndicator()
: Text(
"LOGIN",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
SizedBox(height: 16),
// Register Link
TextButton(
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => RegisterPage())),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => RegisterPage()),
),
child: Text("Don't have an account? Create one"),
),
],