commit
4451a628eb
@ -53,6 +53,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
getUpdateUI(),
|
getUpdateUI(),
|
||||||
Row(
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
getSearchBarUI(),
|
getSearchBarUI(),
|
||||||
],
|
],
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/desktop/pages/remote_page.dart';
|
import 'package:flutter_hbb/desktop/pages/remote_page.dart';
|
||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
|
||||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||||
|
|
||||||
class ConnectionTabPage extends StatefulWidget {
|
class ConnectionTabPage extends StatefulWidget {
|
||||||
@ -18,11 +19,13 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
// refactor List<int> when using multi-tab
|
// refactor List<int> when using multi-tab
|
||||||
// this singleton is only for test
|
// this singleton is only for test
|
||||||
late String connectionId;
|
List<String> connectionIds = List.empty(growable: true);
|
||||||
late TabController tabController;
|
var initialIndex = 0;
|
||||||
|
|
||||||
_ConnectionTabPageState(Map<String, dynamic> params) {
|
_ConnectionTabPageState(Map<String, dynamic> params) {
|
||||||
connectionId = params['id'] ?? "";
|
if (params['id'] != null) {
|
||||||
|
connectionIds.add(params['id']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -34,33 +37,88 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
|
|||||||
// for simplify, just replace connectionId
|
// for simplify, just replace connectionId
|
||||||
if (call.method == "new_remote_desktop") {
|
if (call.method == "new_remote_desktop") {
|
||||||
setState(() {
|
setState(() {
|
||||||
FFI.close();
|
final args = jsonDecode(call.arguments);
|
||||||
connectionId = jsonDecode(call.arguments)["id"];
|
final id = args['id'];
|
||||||
|
final indexOf = connectionIds.indexOf(id);
|
||||||
|
if (indexOf >= 0) {
|
||||||
|
setState(() {
|
||||||
|
initialIndex = indexOf;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
connectionIds.add(id);
|
||||||
|
setState(() {
|
||||||
|
initialIndex = connectionIds.length - 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tabController = TabController(length: 1, vsync: this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Scaffold(
|
||||||
children: [
|
body: DefaultTabController(
|
||||||
TabBar(
|
initialIndex: initialIndex,
|
||||||
controller: tabController,
|
length: connectionIds.length,
|
||||||
isScrollable: true,
|
animationDuration: Duration.zero,
|
||||||
labelColor: Colors.black87,
|
child: Column(
|
||||||
physics: NeverScrollableScrollPhysics(),
|
children: [
|
||||||
tabs: [
|
SizedBox(
|
||||||
Tab(
|
height: 50,
|
||||||
text: connectionId,
|
child: DesktopTitleBar(
|
||||||
|
child: TabBar(
|
||||||
|
isScrollable: true,
|
||||||
|
labelColor: Colors.white,
|
||||||
|
physics: NeverScrollableScrollPhysics(),
|
||||||
|
indicatorColor: Colors.white,
|
||||||
|
tabs: connectionIds
|
||||||
|
.map((e) => Tab(
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(e),
|
||||||
|
SizedBox(
|
||||||
|
width: 4,
|
||||||
|
),
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
onRemoveId(e);
|
||||||
|
},
|
||||||
|
child: Icon(
|
||||||
|
Icons.highlight_remove,
|
||||||
|
size: 20,
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList()),
|
||||||
),
|
),
|
||||||
]),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TabBarView(controller: tabController, children: [
|
child: TabBarView(
|
||||||
RemotePage(key: ValueKey(connectionId), id: connectionId)
|
children: connectionIds
|
||||||
]))
|
.map((e) => Container(
|
||||||
],
|
child: RemotePage(
|
||||||
|
key: ValueKey(e),
|
||||||
|
id: e))) //RemotePage(key: ValueKey(e), id: e))
|
||||||
|
.toList()),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onRemoveId(String id) {
|
||||||
|
final indexOf = connectionIds.indexOf(id);
|
||||||
|
if (indexOf == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
connectionIds.removeAt(indexOf);
|
||||||
|
initialIndex = max(0, initialIndex - 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user