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> { class _ServerListState extends State<ServerList> {
int selectedServer = -1;
List<Server> servers = [ List<Server> servers = [
new Server( new Server(
"example.com", "example.com",
@ -66,9 +67,10 @@ class _ServerListState extends State<ServerList> {
void _updateServerStatus(Server s) { void _updateServerStatus(Server s) {
checkStatus(s.uri).then((value) { checkStatus(s.uri).then((value) {
setState(() { if (value != s.status)
s.status = value; 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 // fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets. // than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by // 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. // the App.build method, and use it to set our appbar title.
title: Text(widget.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(),
), ),
), body: SingleChildScrollView(
floatingActionButton: SpeedDial( // 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, animatedIcon: AnimatedIcons.menu_close,
animatedIconTheme: IconThemeData(size: 20.0), animatedIconTheme: IconThemeData(size: 20.0),
animationSpeed: 150, animationSpeed: 50,
tooltip: 'Menu', tooltip: 'Menu',
backgroundColor: Colors.red.shade900, backgroundColor: Colors.red.shade900,
foregroundColor: Colors.white, foregroundColor: Colors.white,
elevation: 1.0,
shape: CircleBorder(), shape: CircleBorder(),
children: [ children: [
SpeedDialChild( SpeedDialChild(
@ -138,53 +143,94 @@ class _ServerListState extends State<ServerList> {
labelStyle: TextStyle(fontSize: 18.0), labelStyle: TextStyle(fontSize: 18.0),
onTap: _addServer, 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 _settings() {}
void _addServer(){} void _addServer() {
print('poop');
}
List<Widget> _createChildren() { List<Widget> _createChildren() {
return new List<Widget>.generate(servers.length, (int index) { List<Widget> list = new List<Widget>.generate(servers.length, (int index) {
return Container( 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, 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(
color: Colors.white70, color: Colors.white70,
border: Border.all( border: Border.all(
color: Colors.grey, color: Colors.grey,
width: 1, width: 1,
)),
child: Row(children: [
Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: Text(
servers[index].displayName,
style: TextStyle(fontSize: 24),
),
),
), ),
Container( ),
width: 75, child: IconButton(
child: Align( icon: Icon(
alignment: Alignment.center, Icons.add,
child: _generateIcon(servers[index]), size: 42,
// child: Text( color: Colors.black,
// status[index],
// style: TextStyle(fontSize: 24),
// ),
),
), ),
]), onPressed: _addServer,
); ),
}); ),
);
return list;
} }
static Future<ServerStatus> checkStatus(String uri) async { static Future<ServerStatus> checkStatus(String uri) async {