portable service: optimize flutter cm buttons

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-11-10 17:06:27 +08:00
parent 8e1545b432
commit e186eec5df

View File

@ -76,7 +76,6 @@ class _DesktopServerPageState extends State<DesktopServerPage>
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Expanded(child: ConnectionManager()), Expanded(child: ConnectionManager()),
SizedBox.fromSize(size: Size(0, 15.0)),
], ],
), ),
), ),
@ -486,6 +485,8 @@ class _PrivilegeBoardState extends State<_PrivilegeBoard> {
} }
} }
const double bigMargin = 15;
class _CmControlPanel extends StatelessWidget { class _CmControlPanel extends StatelessWidget {
final Client client; final Client client;
@ -503,180 +504,139 @@ class _CmControlPanel extends StatelessWidget {
buildAuthorized(BuildContext context) { buildAuthorized(BuildContext context) {
final bool canElevate = bind.cmCanElevate(); final bool canElevate = bind.cmCanElevate();
final model = Provider.of<ServerModel>(context); final model = Provider.of<ServerModel>(context);
final offstage = !(canElevate && model.showElevation); final showElevation = canElevate && model.showElevation;
final width = offstage ? 200.0 : 100.0; return Column(
return Row( mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Offstage( Offstage(
offstage: offstage, offstage: !showElevation,
child: Ink( child: buildButton(context, color: Colors.green[700], onClick: () {
width: width, handleElevate(context);
height: 40, windowManager.minimize();
decoration: BoxDecoration( },
color: Colors.green[700], icon: Icon(
borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () =>
checkClickTime(client.id, () => handleElevate(context)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.security_sharp, Icons.security_sharp,
color: Colors.white, color: Colors.white,
), ),
Text( text: 'Elevate',
translate("Elevate"), textColor: Colors.white),
style: TextStyle(color: Colors.white),
), ),
], Row(
)),
),
),
Offstage(
offstage: offstage,
child: SizedBox(
width: 30,
)),
Ink(
width: width,
height: 40,
decoration: BoxDecoration(
color: Colors.redAccent, borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () =>
checkClickTime(client.id, () => handleDisconnect(context)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Expanded(
translate("Disconnect"), child: buildButton(context,
style: TextStyle(color: Colors.white), color: Colors.redAccent,
), onClick: handleDisconnect,
text: 'Disconnect',
textColor: Colors.white)),
], ],
)),
) )
], ],
); )
.marginOnly(bottom: showElevation ? 0 : bigMargin)
.marginSymmetric(horizontal: showElevation ? 0 : bigMargin);
} }
buildDisconnected(BuildContext context) { buildDisconnected(BuildContext context) {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Ink( Expanded(
width: 200, child: buildButton(context,
height: 40, color: MyTheme.accent,
decoration: BoxDecoration( onClick: handleClose,
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)), text: 'Close',
child: InkWell( textColor: Colors.white)),
onTap: () => handleClose(context),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
translate("Close"),
style: TextStyle(color: Colors.white),
),
], ],
)), ).marginOnly(bottom: 15).marginSymmetric(horizontal: bigMargin);
)
],
);
} }
buildUnAuthorized(BuildContext context) { buildUnAuthorized(BuildContext context) {
final bool canElevate = bind.cmCanElevate(); final bool canElevate = bind.cmCanElevate();
final model = Provider.of<ServerModel>(context); final model = Provider.of<ServerModel>(context);
final offstage = !(canElevate && model.showElevation); final showElevation = canElevate && model.showElevation;
final width = offstage ? 100.0 : 85.0; return Column(
final spacerWidth = offstage ? 30.0 : 5.0; mainAxisAlignment: MainAxisAlignment.end,
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Offstage( Offstage(
offstage: offstage, offstage: !showElevation,
child: Ink( child: buildButton(context, color: Colors.green[700], onClick: () {
height: 40,
width: width,
decoration: BoxDecoration(
color: Colors.green[700],
borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () => checkClickTime(client.id, () {
handleAccept(context); handleAccept(context);
handleElevate(context); handleElevate(context);
windowManager.minimize(); windowManager.minimize();
}), },
child: Row( text: 'Accept',
mainAxisAlignment: MainAxisAlignment.center, icon: Icon(
children: [
Icon(
Icons.security_sharp, Icons.security_sharp,
color: Colors.white, color: Colors.white,
), ),
Text( textColor: Colors.white),
translate("Accept"),
style: TextStyle(color: Colors.white),
), ),
], Row(
)), mainAxisAlignment: MainAxisAlignment.center,
), children: [
), Expanded(
Offstage( child: buildButton(context, color: MyTheme.accent, onClick: () {
offstage: offstage,
child: SizedBox(
width: spacerWidth,
)),
Ink(
width: width,
height: 40,
decoration: BoxDecoration(
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () => checkClickTime(client.id, () {
handleAccept(context); handleAccept(context);
windowManager.minimize(); windowManager.minimize();
}), }, text: 'Accept', textColor: Colors.white)),
child: Row( Expanded(
mainAxisAlignment: MainAxisAlignment.center, child: buildButton(context,
children: [
Text(
translate("Accept"),
style: TextStyle(color: Colors.white),
),
],
)),
),
SizedBox(
width: spacerWidth,
),
Ink(
width: width,
height: 40,
decoration: BoxDecoration(
color: Colors.transparent, color: Colors.transparent,
borderRadius: BorderRadius.circular(10), border: Border.all(color: Colors.grey),
border: Border.all(color: Colors.grey)), onClick: handleDisconnect,
child: InkWell( text: 'Cancel',
onTap: () => textColor: null)),
checkClickTime(client.id, () => handleDisconnect(context)), ],
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
translate("Cancel"),
style: TextStyle(),
), ),
], ],
)),
) )
], .marginOnly(bottom: showElevation ? 0 : bigMargin)
); .marginSymmetric(horizontal: showElevation ? 0 : bigMargin);
} }
void handleDisconnect(BuildContext context) { buildButton(
BuildContext context, {
required Color? color,
required Function() onClick,
Icon? icon,
BoxBorder? border,
required String text,
required Color? textColor,
}) {
Widget textWidget;
if (icon != null) {
textWidget = Text(
translate(text),
style: TextStyle(color: textColor),
textAlign: TextAlign.center,
);
} else {
textWidget = Expanded(
child: Text(
translate(text),
style: TextStyle(color: textColor),
textAlign: TextAlign.center,
),
);
}
return Container(
height: 35,
decoration: BoxDecoration(
color: color, borderRadius: BorderRadius.circular(4), border: border),
child: InkWell(
onTap: () => checkClickTime(client.id, onClick),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Offstage(offstage: icon == null, child: icon),
textWidget,
],
)),
).marginAll(4);
}
void handleDisconnect() {
bind.cmCloseConnection(connId: client.id); bind.cmCloseConnection(connId: client.id);
} }
@ -691,7 +651,7 @@ class _CmControlPanel extends StatelessWidget {
bind.cmElevatePortable(connId: client.id); bind.cmElevatePortable(connId: client.id);
} }
void handleClose(BuildContext context) async { void handleClose() async {
await bind.cmRemoveDisconnectedConnection(connId: client.id); await bind.cmRemoveDisconnectedConnection(connId: client.id);
if (await bind.cmGetClientsLength() == 0) { if (await bind.cmGetClientsLength() == 0) {
windowManager.close(); windowManager.close();