Build APK / build (push) Successful in 2m49s
- Modèle : champ bluemap_url + ConnectInfo (adresse, version, vocal, modpack)
- API : connectInfo() sur /api/servers/{id}/connect (URL mrpack rendue absolue)
- Écran détail : carte BlueMap (WebView, état vide si serveur éteint) + carte Se connecter (copie adresse, vocal, download/copie du .mrpack)
- dep webview_flutter
136 lines
4.7 KiB
Dart
136 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../models.dart';
|
|
|
|
/// Carte « Se connecter » : adresse, version/loader, chat vocal, et lien du
|
|
/// modpack (.mrpack) pour les joueurs PC.
|
|
class ConnectCard extends StatelessWidget {
|
|
const ConnectCard({super.key, required this.info, required this.loading});
|
|
|
|
final ConnectInfo? info;
|
|
final bool loading;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final i = info;
|
|
return Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(Icons.sports_esports_outlined, size: 20,
|
|
color: Theme.of(context).colorScheme.primary),
|
|
const SizedBox(width: 8),
|
|
Text('Se connecter', style: Theme.of(context).textTheme.titleMedium),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
if (loading && i == null)
|
|
const Center(child: Padding(padding: EdgeInsets.all(8), child: CircularProgressIndicator()))
|
|
else if (i == null)
|
|
const Text('Infos de connexion indisponibles.')
|
|
else ...[
|
|
if ((i.address ?? '').isNotEmpty)
|
|
_Row(
|
|
icon: Icons.dns_outlined,
|
|
label: 'Adresse',
|
|
value: i.address!,
|
|
onCopy: () => _copy(context, i.address!, 'Adresse copiée'),
|
|
),
|
|
if ((i.mcVersion ?? '').isNotEmpty)
|
|
_Row(
|
|
icon: Icons.layers_outlined,
|
|
label: 'Version',
|
|
value: '${i.mcVersion}${(i.loader ?? '').isNotEmpty ? ' · ${i.loader}' : ''}',
|
|
),
|
|
if (i.voiceChatPort != null)
|
|
_Row(
|
|
icon: Icons.mic_outlined,
|
|
label: 'Chat vocal',
|
|
value: 'Simple Voice Chat (UDP ${i.voiceChatPort})',
|
|
),
|
|
if (i.hasPack) ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: FilledButton.tonalIcon(
|
|
onPressed: () => launchUrl(Uri.parse(i.mrpackUrl!),
|
|
mode: LaunchMode.externalApplication),
|
|
icon: const Icon(Icons.download, size: 18),
|
|
label: const Text('Modpack (.mrpack)'),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
OutlinedButton.icon(
|
|
onPressed: () => _copy(context, i.mrpackUrl!, 'Lien du modpack copié'),
|
|
icon: const Icon(Icons.copy, size: 18),
|
|
label: const Text('Copier'),
|
|
),
|
|
],
|
|
),
|
|
if (i.instructions != null && i.instructions!.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
for (final step in i.instructions!)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
child: Text('• $step', style: Theme.of(context).textTheme.bodySmall),
|
|
),
|
|
],
|
|
],
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _copy(BuildContext context, String text, String msg) {
|
|
Clipboard.setData(ClipboardData(text: text));
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
|
}
|
|
}
|
|
|
|
class _Row extends StatelessWidget {
|
|
const _Row({required this.icon, required this.label, required this.value, this.onCopy});
|
|
|
|
final IconData icon;
|
|
final String label;
|
|
final String value;
|
|
final VoidCallback? onCopy;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, size: 20, color: Theme.of(context).colorScheme.primary),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label, style: Theme.of(context).textTheme.labelMedium),
|
|
Text(value, style: Theme.of(context).textTheme.bodyLarge),
|
|
],
|
|
),
|
|
),
|
|
if (onCopy != null)
|
|
IconButton(
|
|
tooltip: 'Copier',
|
|
icon: const Icon(Icons.copy, size: 18),
|
|
onPressed: onCopy,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|