Made the Server Entries Selectable #12

Merged
Hugo Bayer merged 1 commit from Hugo/2801/MadeEntriesSelectable into master 2020-01-28 13:25:03 +00:00

View file

@ -28,6 +28,7 @@ class ServerList extends StatefulWidget {
}
class _ServerListState extends State<ServerList> {
int selectedServer = -1;
List<Server> servers = [
new Server(
"example.com",
@ -66,9 +67,10 @@ class _ServerListState extends State<ServerList> {
void _updateServerStatus(Server s) {
checkStatus(s.uri).then((value) {
setState(() {
s.status = value;
});
if (value != s.status)
setState(() {
s.status = value;
});
});
}
@ -85,41 +87,44 @@ class _ServerListState extends State<ServerList> {
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: SingleChildScrollView(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.start,
children: _createChildren(),
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
),
floatingActionButton: SpeedDial(
body: SingleChildScrollView(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.start,
children: _createChildren(),
),
),
floatingActionButton: FloatingActionButton(
shape: CircleBorder(),
child: Icon(Icons.settings),
)
/*SpeedDial(
animatedIcon: AnimatedIcons.menu_close,
animatedIconTheme: IconThemeData(size: 20.0),
animationSpeed: 150,
animationSpeed: 50,
tooltip: 'Menu',
backgroundColor: Colors.red.shade900,
foregroundColor: Colors.white,
elevation: 1.0,
shape: CircleBorder(),
children: [
SpeedDialChild(
@ -138,53 +143,94 @@ class _ServerListState extends State<ServerList> {
labelStyle: TextStyle(fontSize: 18.0),
onTap: _addServer,
),
],
), // This trailing comma makes auto-formatting nicer for build methods.
);
],*/
// This trailing comma makes auto-formatting nicer for build methods.
);
}
void _settings() {}
void _addServer(){}
void _addServer() {
print('poop');
}
List<Widget> _createChildren() {
return new List<Widget>.generate(servers.length, (int index) {
return Container(
List<Widget> list = new List<Widget>.generate(servers.length, (int index) {
Widget info = Row(children: [
Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
servers[index].displayName,
style: TextStyle(fontSize: 24),
),
),
),
Container(
width: 50,
height: 50,
child: Align(
alignment: Alignment.center,
child: _generateIcon(servers[index]),
),
),
]);
if (index == selectedServer) {
info = Column(
children: [
info,
Container(
decoration: BoxDecoration(border: Border(top: BorderSide(color: Colors.grey))),
),
Text('Ping: 1111'),
],
);
}
return GestureDetector(
onTap: () {
setState(() {
selectedServer = index;
});
print(index.toString() + " clicked");
},
child: Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(2.0),
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.white70,
border: Border.all(
color: Colors.grey,
width: 1,
),
),
child: info),
);
});
list.add(
Container(
height: 75,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(2.0),
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.white70,
border: Border.all(
color: Colors.grey,
width: 1,
)),
child: Row(children: [
Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
servers[index].displayName,
style: TextStyle(fontSize: 24),
),
),
color: Colors.white70,
border: Border.all(
color: Colors.grey,
width: 1,
),
Container(
width: 75,
child: Align(
alignment: Alignment.center,
child: _generateIcon(servers[index]),
// child: Text(
// status[index],
// style: TextStyle(fontSize: 24),
// ),
),
),
child: IconButton(
icon: Icon(
Icons.add,
size: 42,
color: Colors.black,
),
]),
);
});
onPressed: _addServer,
),
),
);
return list;
}
static Future<ServerStatus> checkStatus(String uri) async {