修复flutter analyze提示,更新版本至v1.0.0-Beta4.8

This commit is contained in:
2026-06-21 21:20:29 +08:00
parent 2de7d5269e
commit ae8fe7f31b
6 changed files with 90 additions and 33 deletions

View File

@@ -13,7 +13,7 @@ import (
func main() { func main() {
monitor.Init(2000) monitor.Init(2000)
monitor.Infof("Starting Hightube Server v1.0.0-Beta4.7") monitor.Infof("Starting Hightube Server v1.0.0-Beta4.8")
// Initialize Database and run auto-migrations // Initialize Database and run auto-migrations
db.InitDB() db.InitDB()

View File

@@ -12,7 +12,7 @@ class LoginPage extends StatefulWidget {
const LoginPage({super.key}); const LoginPage({super.key});
@override @override
_LoginPageState createState() => _LoginPageState(); State<LoginPage> createState() => _LoginPageState();
} }
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends State<LoginPage> {
@@ -64,9 +64,9 @@ class _LoginPageState extends State<LoginPage> {
if (!mounted) { if (!mounted) {
return; return;
} }
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(
SnackBar(content: Text(l10n.networkError)), context,
); ).showSnackBar(SnackBar(content: Text(l10n.networkError)));
} finally { } finally {
if (mounted) setState(() => _isLoading = false); if (mounted) setState(() => _isLoading = false);
} }
@@ -177,7 +177,7 @@ class _LoginPageState extends State<LoginPage> {
TextButton( TextButton(
onPressed: () => Navigator.push( onPressed: () => Navigator.push(
context, context,
MaterialPageRoute(builder: (_) => RegisterPage()), MaterialPageRoute(builder: (_) => const RegisterPage()),
), ),
child: Text(l10n.dontHaveAccount), child: Text(l10n.dontHaveAccount),
), ),

View File

@@ -6,8 +6,10 @@ import '../providers/settings_provider.dart';
import '../services/api_service.dart'; import '../services/api_service.dart';
class RegisterPage extends StatefulWidget { class RegisterPage extends StatefulWidget {
const RegisterPage({super.key});
@override @override
_RegisterPageState createState() => _RegisterPageState(); State<RegisterPage> createState() => _RegisterPageState();
} }
class _RegisterPageState extends State<RegisterPage> { class _RegisterPageState extends State<RegisterPage> {
@@ -18,7 +20,9 @@ class _RegisterPageState extends State<RegisterPage> {
void _handleRegister() async { void _handleRegister() async {
final l10n = AppLocalizations.of(context)!; final l10n = AppLocalizations.of(context)!;
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) { if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.fillAllFields))); ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.fillAllFields)));
return; return;
} }
@@ -27,16 +31,32 @@ class _RegisterPageState extends State<RegisterPage> {
final api = ApiService(settings, null); final api = ApiService(settings, null);
try { try {
final response = await api.register(_usernameController.text, _passwordController.text); final response = await api.register(
_usernameController.text,
_passwordController.text,
);
if (!mounted) {
return;
}
if (response.statusCode == 201) { if (response.statusCode == 201) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.accountCreated))); ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.accountCreated)));
Navigator.pop(context); Navigator.pop(context);
} else { } else {
final error = jsonDecode(response.body)['error'] ?? "Registration Failed"; final error =
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(error))); jsonDecode(response.body)['error'] ?? "Registration Failed";
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(error)));
} }
} catch (e) { } catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(l10n.networkError))); if (!mounted) {
return;
}
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(l10n.networkError)));
} finally { } finally {
if (mounted) setState(() => _isLoading = false); if (mounted) setState(() => _isLoading = false);
} }
@@ -55,11 +75,17 @@ class _RegisterPageState extends State<RegisterPage> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.person_add_outlined, size: 64, color: Theme.of(context).colorScheme.primary), Icon(
Icons.person_add_outlined,
size: 64,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 24), const SizedBox(height: 24),
Text( Text(
l10n.joinHightube, l10n.joinHightube,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(fontWeight: FontWeight.bold), style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
), ),
const SizedBox(height: 48), const SizedBox(height: 48),
TextField( TextField(
@@ -67,7 +93,9 @@ class _RegisterPageState extends State<RegisterPage> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: l10n.desiredUsername, labelText: l10n.desiredUsername,
prefixIcon: const Icon(Icons.person), prefixIcon: const Icon(Icons.person),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)), border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@@ -77,7 +105,9 @@ class _RegisterPageState extends State<RegisterPage> {
decoration: InputDecoration( decoration: InputDecoration(
labelText: l10n.password, labelText: l10n.password,
prefixIcon: const Icon(Icons.lock), prefixIcon: const Icon(Icons.lock),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)), border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
), ),
const SizedBox(height: 32), const SizedBox(height: 32),
@@ -87,9 +117,16 @@ class _RegisterPageState extends State<RegisterPage> {
child: ElevatedButton( child: ElevatedButton(
onPressed: _isLoading ? null : _handleRegister, onPressed: _isLoading ? null : _handleRegister,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
), ),
child: _isLoading ? const CircularProgressIndicator() : Text(l10n.register, style: const TextStyle(fontWeight: FontWeight.bold)), child: _isLoading
? const CircularProgressIndicator()
: Text(
l10n.register,
style: const TextStyle(fontWeight: FontWeight.bold),
),
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),

View File

@@ -393,7 +393,7 @@ class _SettingsPageState extends State<SettingsPage> {
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
), ),
Text( Text(
"Version: 1.0.0-beta4.1", "Version: 1.0.0-beta4.8",
style: TextStyle(color: Colors.grey), style: TextStyle(color: Colors.grey),
), ),
Text( Text(

View File

@@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart';
class ChatMessage { class ChatMessage {
@@ -38,27 +39,46 @@ class ChatMessage {
class ChatService { class ChatService {
WebSocketChannel? _channel; WebSocketChannel? _channel;
final StreamController<ChatMessage> _messageController = StreamController<ChatMessage>.broadcast(); final StreamController<ChatMessage> _messageController =
StreamController<ChatMessage>.broadcast();
Stream<ChatMessage> get messages => _messageController.stream; Stream<ChatMessage> get messages => _messageController.stream;
void connect(String baseUrl, String roomId, String username) { void connect(String baseUrl, String roomId, String username) {
final wsUri = Uri.parse(baseUrl).replace(scheme: 'ws', path: '/api/ws/room/$roomId', queryParameters: {'username': username}); final wsUri = Uri.parse(baseUrl).replace(
scheme: 'ws',
path: '/api/ws/room/$roomId',
queryParameters: {'username': username},
);
_channel = WebSocketChannel.connect(wsUri); _channel = WebSocketChannel.connect(wsUri);
_channel!.stream.listen((data) { _channel!.stream.listen(
final json = jsonDecode(data); (data) {
_messageController.add(ChatMessage.fromJson(json)); final json = jsonDecode(data);
}, onError: (err) { _messageController.add(ChatMessage.fromJson(json));
print("[WS ERROR] $err"); },
}, onDone: () { onError: (err) {
print("[WS DONE] Connection closed"); debugPrint("[WS ERROR] $err");
}); },
onDone: () {
debugPrint("[WS DONE] Connection closed");
},
);
} }
void sendMessage(String content, String username, String roomId, {String type = 'chat'}) { void sendMessage(
String content,
String username,
String roomId, {
String type = 'chat',
}) {
if (_channel != null) { if (_channel != null) {
final msg = ChatMessage(type: type, username: username, content: content, roomId: roomId); final msg = ChatMessage(
type: type,
username: username,
content: content,
roomId: roomId,
);
_channel!.sink.add(jsonEncode(msg.toJson())); _channel!.sink.add(jsonEncode(msg.toJson()));
} }
} }

View File

@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 1.0.0-beta4.7 version: 1.0.0-beta4.8
environment: environment:
sdk: ^3.11.1 sdk: ^3.11.1