rustdesk/flutter/lib/mobile/pages/home_page.dart

167 lines
4.9 KiB
Dart
Raw Normal View History

2020-11-15 20:04:05 +08:00
import 'package:flutter/material.dart';
2022-05-24 23:33:00 +08:00
import 'package:flutter_hbb/mobile/pages/server_page.dart';
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
import 'package:get/get.dart';
2022-05-24 23:33:00 +08:00
import '../../common.dart';
import '../../common/widgets/chat_page.dart';
2024-04-16 22:53:01 +08:00
import '../../models/platform_model.dart';
import 'connection_page.dart';
2020-11-15 20:04:05 +08:00
abstract class PageShape extends Widget {
final String title = "";
final Widget icon = Icon(null);
final List<Widget> appBarActions = [];
}
2020-11-15 20:04:05 +08:00
class HomePage extends StatefulWidget {
static final homeKey = GlobalKey<HomePageState>();
2022-08-05 20:29:43 +08:00
HomePage() : super(key: homeKey);
2020-11-15 20:04:05 +08:00
@override
HomePageState createState() => HomePageState();
2020-11-15 20:04:05 +08:00
}
class HomePageState extends State<HomePage> {
var _selectedIndex = 0;
int get selectedIndex => _selectedIndex;
2022-03-24 17:58:33 +08:00
final List<PageShape> _pages = [];
int _chatPageTabIndex = -1;
bool get isChatPageCurrentTab => isAndroid
? _selectedIndex == _chatPageTabIndex
: false; // change this when ios have chat page
2022-03-24 17:58:33 +08:00
2022-08-04 17:24:02 +08:00
void refreshPages() {
setState(() {
initPages();
});
}
2022-03-24 17:58:33 +08:00
@override
void initState() {
super.initState();
2022-08-04 17:24:02 +08:00
initPages();
}
void initPages() {
_pages.clear();
2024-04-16 22:53:01 +08:00
if (!bind.isIncomingOnly()) _pages.add(ConnectionPage());
2024-04-17 12:48:27 +08:00
if (isAndroid && !bind.isOutgoingOnly()) {
_chatPageTabIndex = _pages.length;
_pages.addAll([ChatPage(type: ChatPageType.mobileMain), ServerPage()]);
2022-03-24 17:58:33 +08:00
}
_pages.add(SettingsPage());
}
@override
Widget build(BuildContext context) {
2022-03-01 15:46:59 +08:00
return WillPopScope(
onWillPop: () async {
if (_selectedIndex != 0) {
setState(() {
_selectedIndex = 0;
});
} else {
return true;
}
return false;
},
child: Scaffold(
2022-09-23 16:31:50 +08:00
// backgroundColor: MyTheme.grayBg,
2022-03-01 15:46:59 +08:00
appBar: AppBar(
centerTitle: true,
title: appTitle(),
2022-03-01 15:46:59 +08:00
actions: _pages.elementAt(_selectedIndex).appBarActions,
),
bottomNavigationBar: BottomNavigationBar(
key: navigationBarKey,
2022-03-01 15:46:59 +08:00
items: _pages
.map((page) =>
BottomNavigationBarItem(icon: page.icon, label: page.title))
.toList(),
currentIndex: _selectedIndex,
type: BottomNavigationBarType.fixed,
2022-09-23 16:31:50 +08:00
selectedItemColor: MyTheme.accent, //
2022-03-01 15:46:59 +08:00
unselectedItemColor: MyTheme.darkGray,
onTap: (index) => setState(() {
// close chat overlay when go chat page
if (_selectedIndex != index) {
_selectedIndex = index;
if (isChatPageCurrentTab) {
gFFI.chatModel.hideChatIconOverlay();
gFFI.chatModel.hideChatWindowOverlay();
gFFI.chatModel.mobileClearClientUnread(
gFFI.chatModel.currentKey.connId);
}
}
2022-03-01 15:46:59 +08:00
}),
),
body: _pages.elementAt(_selectedIndex),
2022-03-01 15:46:59 +08:00
));
}
Widget appTitle() {
final currentUser = gFFI.chatModel.currentUser;
final currentKey = gFFI.chatModel.currentKey;
if (isChatPageCurrentTab &&
currentUser != null &&
currentKey.peerId.isNotEmpty) {
final connected =
gFFI.serverModel.clients.any((e) => e.id == currentKey.connId);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Tooltip(
message: currentKey.isOut
2023-07-10 23:02:26 +08:00
? translate('Outgoing connection')
: translate('Incoming connection'),
child: Icon(
currentKey.isOut
? Icons.call_made_rounded
: Icons.call_received_rounded,
),
),
Expanded(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${currentUser.firstName} ${currentUser.id}",
),
if (connected)
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color.fromARGB(255, 133, 246, 199)),
).marginSymmetric(horizontal: 2),
],
),
),
),
],
);
}
2024-04-16 22:53:01 +08:00
return Text(bind.mainGetAppNameSync());
}
}
2022-03-24 17:58:33 +08:00
class WebHomePage extends StatelessWidget {
final connectionPage = ConnectionPage();
@override
Widget build(BuildContext context) {
return Scaffold(
2022-09-23 16:31:50 +08:00
// backgroundColor: MyTheme.grayBg,
2022-03-24 17:58:33 +08:00
appBar: AppBar(
centerTitle: true,
2024-04-16 22:53:01 +08:00
title: Text(bind.mainGetAppNameSync()),
2022-03-24 17:58:33 +08:00
actions: connectionPage.appBarActions,
),
body: connectionPage,
);
}
}