pcast/lib/pages/server_info_page.dart

72 lines
2.1 KiB
Dart

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:pcast/models/monitor_model.dart';
class ServerInfoPage extends StatefulWidget {
// const ServerInfoComponent({Key? key, required this.info}) : super(key: key);
// final MonitorModel info;
// @override
// Widget build(BuildContext context) {
// return Column(
// children: [
// Text(' CPU: ${info.cpu}'),
// Text('Memory: ${info.memory}'),
// Text(' Disk: ${info.disk}'),
// ],
// );
// }
// }
const ServerInfoPage({super.key});
@override
State<ServerInfoPage> createState() => _ServerInfoPageState();
}
class _ServerInfoPageState extends State<ServerInfoPage> {
@override
void initState() {
super.initState();
getmemory();
}
Future<MonitorModel> getmemory() async {
final dio = Modular.get<Dio>();
final response = await dio.get('https://api.pcastlivetv.com/health');
return MonitorModel.fromJson(response.data);
}
@override
Widget build(BuildContext context) {
return FutureBuilder<MonitorModel>(
future: getmemory(),
builder: (BuildContext context, AsyncSnapshot<MonitorModel> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: Text('Please wait its loading...'));
} else {
if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else {
return Scaffold(
appBar: AppBar(title: const Text('Home Page')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Memory: ${snapshot.data?.memory?.toStringAsFixed(2)}%'),
Text('CPU: ${snapshot.data?.cpu?.toStringAsFixed(2)}%'),
Text('Disk: ${snapshot.data?.disk?.toStringAsFixed(2)}%'),
],
),
),
);
}
}
},
);
}
}