You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
Dart
75 lines
1.9 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|
import 'package:dio/dio.dart';
|
|
import '../../core/config.dart';
|
|
|
|
class PingTestScreen extends StatefulWidget {
|
|
const PingTestScreen({super.key});
|
|
|
|
@override
|
|
State<PingTestScreen> createState() => _PingTestScreenState();
|
|
}
|
|
|
|
class _PingTestScreenState extends State<PingTestScreen> {
|
|
String? _result;
|
|
bool _loading = false;
|
|
|
|
Future<void> _pingServer() async {
|
|
setState(() {
|
|
_loading = true;
|
|
_result = null;
|
|
});
|
|
|
|
try {
|
|
final res = await Dio(BaseOptions(
|
|
baseUrl: AppConfig.backendBaseUrl,
|
|
headers: const {
|
|
'Accept': 'application/json',
|
|
},
|
|
contentType: Headers.jsonContentType,
|
|
validateStatus: (s) => s != null && s < 500,
|
|
)).post('', data: {'action': 'ping'});
|
|
|
|
setState(() {
|
|
_result = '✅ Antwort: ${res.data}';
|
|
});
|
|
} catch (e) {
|
|
setState(() {
|
|
_result = '❌ Fehler: $e';
|
|
});
|
|
} finally {
|
|
setState(() => _loading = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Ping-Test')),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
ElevatedButton.icon(
|
|
icon: const Icon(Icons.wifi_tethering),
|
|
label: const Text('Ping-Server'),
|
|
onPressed: _loading ? null : _pingServer,
|
|
),
|
|
const SizedBox(height: 20),
|
|
if (_loading) const CircularProgressIndicator(),
|
|
if (_result != null)
|
|
SelectableText(
|
|
_result!,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|