rustdesk/flutter/lib/desktop/pages/desktop_home_page.dart

237 lines
6.3 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:flutter/material.dart' hide MenuItem;
import 'package:flutter_hbb/common.dart';
2022-05-29 04:39:12 +08:00
import 'package:flutter_hbb/desktop/pages/connection_page.dart';
2022-05-29 19:55:50 +08:00
import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
import 'package:flutter_hbb/models/model.dart';
import 'package:provider/provider.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
2022-05-23 16:44:23 +08:00
class DesktopHomePage extends StatefulWidget {
DesktopHomePage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _DesktopHomePageState();
}
2022-05-29 19:55:50 +08:00
const borderColor = Color(0xFF2F65BA);
class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
2022-05-23 16:44:23 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
2022-05-29 19:55:50 +08:00
body: Column(
children: [
DesktopTitleBar(
child: Center(
child: Text(
"RustDesk",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
2022-05-29 19:55:50 +08:00
),
Expanded(
child: Container(
child: Row(
children: [
Flexible(
child: buildServerInfo(context),
flex: 1,
),
SizedBox(
width: 16.0,
),
Flexible(
child: buildServerBoard(context),
flex: 4,
),
],
),
),
2022-05-29 19:55:50 +08:00
),
],
),
);
}
buildServerInfo(BuildContext context) {
return ChangeNotifierProvider.value(
value: FFI.serverModel,
2022-05-29 10:25:36 +08:00
child: Container(
decoration: BoxDecoration(color: MyTheme.white),
child: Column(
children: [
buildTip(context),
buildIDBoard(context),
buildPasswordBoard(context),
],
),
),
);
}
buildServerBoard(BuildContext context) {
2022-05-29 10:25:36 +08:00
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
2022-05-29 10:25:36 +08:00
children: [
// buildControlPanel(context),
// buildRecentSession(context),
Expanded(child: ConnectionPage())
2022-05-29 10:25:36 +08:00
],
);
}
buildIDBoard(BuildContext context) {
final model = FFI.serverModel;
2022-05-29 10:25:36 +08:00
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Container(
width: 3,
height: 70,
decoration: BoxDecoration(color: MyTheme.accent),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
translate("ID"),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
),
TextFormField(
controller: model.serverId,
),
],
),
),
2022-05-29 10:25:36 +08:00
),
],
),
);
}
buildPasswordBoard(BuildContext context) {
final model = FFI.serverModel;
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0, horizontal: 16.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Container(
width: 3,
height: 70,
decoration: BoxDecoration(color: MyTheme.accent),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
translate("Password"),
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
),
TextFormField(
controller: model.serverPasswd,
),
],
),
),
2022-05-29 10:25:36 +08:00
),
],
),
);
}
buildTip(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
translate("Your Desktop"),
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
SizedBox(
height: 8.0,
),
Text(
translate("desk_tip"),
overflow: TextOverflow.clip,
style: TextStyle(fontSize: 14),
)
],
),
);
2022-05-23 16:44:23 +08:00
}
2022-05-29 10:25:36 +08:00
buildControlPanel(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), color: MyTheme.white),
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(translate("Control Remote Desktop")),
Form(
child: Column(
children: [
TextFormField(
controller: TextEditingController(),
inputFormatters: [],
)
],
))
],
),
);
}
buildRecentSession(BuildContext context) {
return Center(child: Text("waiting implementation"));
}
@override
void onTrayMenuItemClick(MenuItem menuItem) {
print("click ${menuItem.key}");
switch (menuItem.key) {
case "quit":
exit(0);
case "show":
windowManager.show();
break;
default:
break;
}
}
@override
void initState() {
super.initState();
trayManager.addListener(this);
}
@override
void dispose() {
trayManager.removeListener(this);
super.dispose();
}
2022-05-23 16:44:23 +08:00
}