Changed seperate string lists to one server list, added that every 5 seconds the icons are randomized finished the generate icon method #8
2 changed files with 75 additions and 28 deletions
|
@ -5,9 +5,9 @@ enum ServerStatus{
|
||||||
class Server {
|
class Server {
|
||||||
String uri;
|
String uri;
|
||||||
String displayName;
|
String displayName;
|
||||||
ServerStatus status;
|
ServerStatus status = ServerStatus.unknown;
|
||||||
|
|
||||||
Server(this.uri, this.displayName);
|
Server(this.displayName,this.uri,);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:server_pinger/server.dart';
|
||||||
|
|
||||||
class ServerList extends StatefulWidget {
|
class ServerList extends StatefulWidget {
|
||||||
ServerList({Key key, this.title}) : super(key: key);
|
ServerList({Key key, this.title}) : super(key: key);
|
||||||
|
@ -21,10 +23,52 @@ class ServerList extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ServerListState extends State<ServerList> {
|
class _ServerListState extends State<ServerList> {
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {});
|
|
||||||
|
List<Server> server = [
|
||||||
|
new Server(
|
||||||
|
"example.com",
|
||||||
|
"http://example.com",
|
||||||
|
),
|
||||||
|
new Server(
|
||||||
|
"youtube.com",
|
||||||
|
"https://youtube.com",
|
||||||
|
),
|
||||||
|
new Server(
|
||||||
|
"My VPS",
|
||||||
|
"https://vps1.kescher.at",
|
||||||
|
),
|
||||||
|
new Server(
|
||||||
|
"Raspberry Pi",
|
||||||
|
"https://pi.kescher.at/isup",
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
Timer timer;
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
|
||||||
|
_ServerListState(){
|
||||||
|
|
||||||
|
timer = new Timer.periodic(new Duration(seconds: 5), (timer){
|
||||||
|
server.forEach(_updateServerStatus);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateServerStatus(Server server){
|
||||||
|
setState(() {
|
||||||
|
server.status=ServerStatus.values[rnd.nextInt(ServerStatus.values.length-1)+1];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateUI() {
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// This method is rerun every time setState is called, for instance as done
|
// This method is rerun every time setState is called, for instance as done
|
||||||
|
@ -62,31 +106,24 @@ class _ServerListState extends State<ServerList> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _incrementCounter,
|
onPressed: _updateUI,
|
||||||
tooltip: 'Increment',
|
tooltip: 'Increment',
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<Widget> _createChildren() {
|
List<Widget> _createChildren() {
|
||||||
List<String> shownIdentifier = [
|
|
||||||
"example.com",
|
|
||||||
"youtube.com",
|
|
||||||
"My VPS",
|
|
||||||
"Raspberry Pi"
|
|
||||||
];
|
|
||||||
List<String> url = [
|
|
||||||
"http://example.com",
|
|
||||||
"https://youtube.com",
|
|
||||||
"https://vps1.kescher.at",
|
|
||||||
"https://pi.kescher.at/isup"
|
|
||||||
];
|
|
||||||
List<String> status = ["ON", "OFF?", "ON", "ON"];
|
List<String> status = ["ON", "OFF?", "ON", "ON"];
|
||||||
return new List<Widget>.generate(shownIdentifier.length, (int index) {
|
return new List<Widget>.generate(server.length, (int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 75,
|
height: 75,
|
||||||
width: MediaQuery.of(context).size.width,
|
width: MediaQuery
|
||||||
|
.of(context)
|
||||||
|
.size
|
||||||
|
.width,
|
||||||
margin: EdgeInsets.all(2.0),
|
margin: EdgeInsets.all(2.0),
|
||||||
padding: EdgeInsets.all(10.0),
|
padding: EdgeInsets.all(10.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
@ -100,7 +137,7 @@ class _ServerListState extends State<ServerList> {
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.centerLeft,
|
alignment: Alignment.centerLeft,
|
||||||
child: Text(
|
child: Text(
|
||||||
shownIdentifier[index],
|
server[index].displayName,
|
||||||
style: TextStyle(fontSize: 24),
|
style: TextStyle(fontSize: 24),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -109,7 +146,7 @@ class _ServerListState extends State<ServerList> {
|
||||||
width: 75,
|
width: 75,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: _generateIcon(),
|
child: _generateIcon(server[index]),
|
||||||
// child: Text(
|
// child: Text(
|
||||||
// status[index],
|
// status[index],
|
||||||
// style: TextStyle(fontSize: 24),
|
// style: TextStyle(fontSize: 24),
|
||||||
|
@ -121,12 +158,22 @@ class _ServerListState extends State<ServerList> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon _generateIcon() {
|
Icon _generateIcon(Server server) {
|
||||||
Icon icon = new Icon(
|
if (server.status == ServerStatus.unknown)
|
||||||
Icons.check_box_outline_blank,
|
return new Icon(
|
||||||
color: Colors.yellow,
|
Icons.check_box_outline_blank,
|
||||||
);
|
color: Colors.yellow,
|
||||||
new Timer.periodic(new Duration(milliseconds: 500), (timer) {});
|
);
|
||||||
return icon;
|
else if(server.status == ServerStatus.responding)
|
||||||
|
return new Icon(
|
||||||
|
Icons.check_box,
|
||||||
|
color: Colors.green,
|
||||||
|
);
|
||||||
|
else
|
||||||
|
return new Icon(
|
||||||
|
Icons.indeterminate_check_box,
|
||||||
|
color: Colors.red,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue