diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index e399effc2..34a8f94c4 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -106,9 +106,11 @@ class DesktopServerPage extends StatefulWidget implements PageShape { State createState() => _DesktopServerPageState(); } -class _DesktopServerPageState extends State { +class _DesktopServerPageState extends State + with AutomaticKeepAliveClientMixin { @override Widget build(BuildContext context) { + super.build(context); return ChangeNotifierProvider.value( value: gFFI.serverModel, child: Consumer( @@ -124,6 +126,9 @@ class _DesktopServerPageState extends State { ), ))); } + + @override + bool get wantKeepAlive => true; } class ConnectionManager extends StatelessWidget { @@ -131,20 +136,25 @@ class ConnectionManager extends StatelessWidget { Widget build(BuildContext context) { final serverModel = Provider.of(context); // test case: - // serverModel.clients.clear(); - // serverModel.clients[0] = Client(false, false, "Readmi-M21sdfsdf", "123123123", true, false, false); - return DefaultTabController( - length: serverModel.clients.length, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: kTextTabBarHeight, - child: TabBar( - isScrollable: true, - tabs: serverModel.clients.entries - .map((entry) => buildTab(entry)) - .toList(growable: false)), + serverModel.clients.clear(); + serverModel.clients[0] = Client( + false, false, "Readmi-M21sdfsdf", "123123123", true, false, false); + return serverModel.clients.isEmpty + ? Center( + child: Text(translate("Waiting")), + ) + : DefaultTabController( + length: serverModel.clients.length, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: kTextTabBarHeight, + child: TabBar( + isScrollable: true, + tabs: serverModel.clients.entries + .map((entry) => buildTab(entry)) + .toList(growable: false)), ), Expanded( child: TabBarView( @@ -321,10 +331,12 @@ class _CmControlPanel extends StatelessWidget { @override Widget build(BuildContext context) { - return client.authorized ? buildAuthorized() : buildUnAuthorized(); + return client.authorized + ? buildAuthorized(context) + : buildUnAuthorized(context); } - buildAuthorized() { + buildAuthorized(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -334,7 +346,7 @@ class _CmControlPanel extends StatelessWidget { decoration: BoxDecoration( color: Colors.redAccent, borderRadius: BorderRadius.circular(10)), child: InkWell( - onTap: handleDisconnect, + onTap: () => handleDisconnect(context), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -349,7 +361,7 @@ class _CmControlPanel extends StatelessWidget { ); } - buildUnAuthorized() { + buildUnAuthorized(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -359,7 +371,7 @@ class _CmControlPanel extends StatelessWidget { decoration: BoxDecoration( color: MyTheme.accent, borderRadius: BorderRadius.circular(10)), child: InkWell( - onTap: handleAccept, + onTap: () => handleAccept(context), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -381,7 +393,7 @@ class _CmControlPanel extends StatelessWidget { borderRadius: BorderRadius.circular(10), border: Border.all(color: Colors.grey)), child: InkWell( - onTap: handleCancel, + onTap: () => handleDisconnect(context), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -396,11 +408,14 @@ class _CmControlPanel extends StatelessWidget { ); } - void handleDisconnect() {} + void handleDisconnect(BuildContext context) { + bind.cmCloseConnection(connId: client.id); + } - void handleCancel() {} - - void handleAccept() {} + void handleAccept(BuildContext context) { + final model = Provider.of(context, listen: false); + model.sendLoginResponse(client, true); + } } class PaddingCard extends StatelessWidget { diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index e5465e1e3..9ba85eba1 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -97,9 +97,8 @@ class ServerModel with ChangeNotifier { } final res = await bind.mainCheckClientsLength(length: _clients.length); if (res != null) { - // for test - // debugPrint("clients not match!"); - // updateClientState(res); + debugPrint("clients not match!"); + updateClientState(res); } updatePasswordModel();