2020-11-15 20:04:05 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
import 'package:flutter_hbb/pages/chat_page.dart';
|
2022-02-28 18:29:25 +08:00
|
|
|
import 'package:flutter_hbb/pages/server_page.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
import 'package:flutter_hbb/pages/settings_page.dart';
|
2022-02-28 18:29:25 +08:00
|
|
|
import '../common.dart';
|
2022-04-28 22:44:54 +08:00
|
|
|
import '../widgets/overlay.dart';
|
2022-02-28 21:26:44 +08:00
|
|
|
import 'connection_page.dart';
|
2020-11-15 20:04:05 +08:00
|
|
|
|
2022-02-28 18:29:25 +08:00
|
|
|
abstract class PageShape extends Widget {
|
|
|
|
final String title = "";
|
|
|
|
final Icon icon = Icon(null);
|
|
|
|
final List<Widget> appBarActions = [];
|
|
|
|
}
|
2020-11-15 20:04:05 +08:00
|
|
|
|
2022-07-31 20:42:56 +08:00
|
|
|
final homeKey = GlobalKey<_HomePageState>();
|
|
|
|
|
2022-02-28 18:29:25 +08:00
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
HomePage({Key? key}) : super(key: key);
|
2020-11-15 20:04:05 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
_HomePageState createState() => _HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage> {
|
2022-02-28 18:29:25 +08:00
|
|
|
var _selectedIndex = 0;
|
2022-03-24 17:58:33 +08:00
|
|
|
final List<PageShape> _pages = [];
|
|
|
|
|
2022-07-31 20:42:56 +08:00
|
|
|
void refreshPages() {
|
|
|
|
setState(() {
|
|
|
|
initPages();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-24 17:58:33 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-07-31 20:42:56 +08:00
|
|
|
initPages();
|
|
|
|
}
|
|
|
|
|
|
|
|
void initPages() {
|
|
|
|
_pages.clear();
|
2022-04-15 17:50:15 +08:00
|
|
|
_pages.add(ConnectionPage());
|
2022-04-09 17:31:19 +08:00
|
|
|
if (isAndroid) {
|
2022-07-31 20:42:56 +08:00
|
|
|
_pages.addAll([ChatPage(), ServerPage()]);
|
2022-03-24 17:58:33 +08:00
|
|
|
}
|
|
|
|
_pages.add(SettingsPage());
|
|
|
|
}
|
2022-02-28 18:29:25 +08:00
|
|
|
|
|
|
|
@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(
|
|
|
|
backgroundColor: MyTheme.grayBg,
|
|
|
|
appBar: AppBar(
|
|
|
|
centerTitle: true,
|
|
|
|
title: Text("RustDesk"),
|
|
|
|
actions: _pages.elementAt(_selectedIndex).appBarActions,
|
|
|
|
),
|
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
2022-04-04 14:54:00 +08:00
|
|
|
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,
|
|
|
|
selectedItemColor: MyTheme.accent,
|
|
|
|
unselectedItemColor: MyTheme.darkGray,
|
|
|
|
onTap: (index) => setState(() {
|
2022-03-22 16:40:23 +08:00
|
|
|
// close chat overlay when go chat page
|
2022-03-24 17:58:33 +08:00
|
|
|
if (index == 1 && _selectedIndex != index) {
|
2022-03-22 16:40:23 +08:00
|
|
|
hideChatIconOverlay();
|
|
|
|
hideChatWindowOverlay();
|
|
|
|
}
|
2022-03-01 15:46:59 +08:00
|
|
|
_selectedIndex = index;
|
|
|
|
}),
|
|
|
|
),
|
2022-04-19 17:53:35 +08:00
|
|
|
body: _pages.elementAt(_selectedIndex),
|
2022-03-01 15:46:59 +08:00
|
|
|
));
|
2022-02-28 18:29:25 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-24 17:58:33 +08:00
|
|
|
|
|
|
|
class WebHomePage extends StatelessWidget {
|
|
|
|
final connectionPage = ConnectionPage();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: MyTheme.grayBg,
|
|
|
|
appBar: AppBar(
|
|
|
|
centerTitle: true,
|
2022-04-09 17:31:19 +08:00
|
|
|
title: Text("RustDesk" + (isWeb ? " (Beta) " : "")),
|
2022-03-24 17:58:33 +08:00
|
|
|
actions: connectionPage.appBarActions,
|
|
|
|
),
|
|
|
|
body: connectionPage,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|