From 6e89d8b215890c217ae4dc58f3821aeeec363252 Mon Sep 17 00:00:00 2001 From: Hugo Bayer Date: Tue, 28 Jan 2020 14:24:00 +0100 Subject: [PATCH] Made the Server Entries Selectable --- lib/serverlist.dart | 178 ++++++++++++++++++++++++++++---------------- 1 file changed, 112 insertions(+), 66 deletions(-) diff --git a/lib/serverlist.dart b/lib/serverlist.dart index 12c5507..2338262 100644 --- a/lib/serverlist.dart +++ b/lib/serverlist.dart @@ -28,6 +28,7 @@ class ServerList extends StatefulWidget { } class _ServerListState extends State { + int selectedServer = -1; List servers = [ new Server( "example.com", @@ -66,9 +67,10 @@ class _ServerListState extends State { 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 { // 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 { 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 _createChildren() { - return new List.generate(servers.length, (int index) { - return Container( + List list = new List.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 checkStatus(String uri) async { -- 2.47.0