59 lines
2.0 KiB
Dart
59 lines
2.0 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
void main() {
|
|
runApp(const App());
|
|
}
|
|
|
|
class App extends StatelessWidget {
|
|
const App({super.key});
|
|
|
|
Future<bool> checkApiConnection() async {
|
|
final res = await http.get(
|
|
Uri.parse('http://localhost:5000/db'),
|
|
);
|
|
|
|
final Map<String, dynamic> data = jsonDecode(res.body);
|
|
return data['value'] == 777;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: FutureBuilder<bool>(
|
|
future: checkApiConnection(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const CircularProgressIndicator();
|
|
}
|
|
if (snapshot.hasError) {
|
|
return const Text(
|
|
'API SERVER CONNECTION FAILED',
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
|
|
return const Text(
|
|
'API SERVER CONNECTED',
|
|
style: TextStyle(
|
|
fontSize: 22,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.green,
|
|
letterSpacing: 1.2,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|