Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rustdesk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李朝发
rustdesk
Commits
41a5d53d
Commit
41a5d53d
authored
Sep 08, 2022
by
fufesou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flutter_desktop: refactor GetX in popup menu
Signed-off-by:
fufesou
<
shuanglongchen@yeah.net
>
parent
9b694cba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
74 deletions
+66
-74
popup_menu.dart
flutter/lib/desktop/widgets/popup_menu.dart
+65
-73
remote_menubar.dart
flutter/lib/desktop/widgets/remote_menubar.dart
+1
-1
No files found.
flutter/lib/desktop/widgets/popup_menu.dart
View file @
41a5d53d
...
...
@@ -8,7 +8,7 @@ import './material_mod_popup_menu.dart' as mod_menu;
// https://stackoverflow.com/questions/68318314/flutter-popup-menu-inside-popup-menu
class
PopupMenuChildrenItem
<
T
>
extends
mod_menu
.
PopupMenuEntry
<
T
>
{
const
PopupMenuChildrenItem
({
PopupMenuChildrenItem
({
key
,
this
.
height
=
kMinInteractiveDimension
,
this
.
padding
,
...
...
@@ -43,6 +43,16 @@ class PopupMenuChildrenItem<T> extends mod_menu.PopupMenuEntry<T> {
class
MyPopupMenuItemState
<
T
,
W
extends
PopupMenuChildrenItem
<
T
>>
extends
State
<
W
>
{
RxBool
enabled
=
true
.
obs
;
@override
void
initState
()
{
super
.
initState
();
if
(
widget
.
enabled
!=
null
)
{
enabled
.
value
=
widget
.
enabled
!.
value
;
}
}
@protected
void
handleTap
(
T
value
)
{
widget
.
onTap
?.
call
();
...
...
@@ -56,27 +66,25 @@ class MyPopupMenuItemState<T, W extends PopupMenuChildrenItem<T>>
TextStyle
style
=
widget
.
textStyle
??
popupMenuTheme
.
textStyle
??
theme
.
textTheme
.
subtitle1
!;
return
Obx
(()
{
return
mod_menu
.
PopupMenuButton
<
T
>(
enabled:
widget
.
enabled
!=
null
?
widget
.
enabled
!.
value
:
true
,
position:
widget
.
position
,
offset:
widget
.
offset
,
onSelected:
handleTap
,
itemBuilder:
widget
.
itemBuilder
,
padding:
EdgeInsets
.
zero
,
child:
AnimatedDefaultTextStyle
(
style:
style
,
duration:
kThemeChangeDuration
,
child:
Container
(
alignment:
AlignmentDirectional
.
centerStart
,
constraints:
BoxConstraints
(
minHeight:
widget
.
height
),
padding:
widget
.
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
16
)
,
child:
widget
.
child
,
return
Obx
(()
=>
mod_menu
.
PopupMenuButton
<
T
>(
enabled:
enabled
.
value
,
position:
widget
.
position
,
offset:
widget
.
offset
,
onSelected:
handleTap
,
itemBuilder:
widget
.
itemBuilder
,
padding:
EdgeInsets
.
zero
,
child:
AnimatedDefaultTextStyle
(
style:
style
,
duration:
kThemeChangeDuration
,
child:
Container
(
alignment:
AlignmentDirectional
.
centerStart
,
constraints:
BoxConstraints
(
minHeight:
widget
.
height
)
,
padding:
widget
.
padding
??
const
EdgeInsets
.
symmetric
(
horizontal:
16
),
child:
widget
.
child
,
)
,
),
),
);
});
));
}
}
...
...
@@ -342,7 +350,7 @@ typedef SwitchSetter = Future<void> Function(bool);
abstract
class
MenuEntrySwitchBase
<
T
>
extends
MenuEntryBase
<
T
>
{
final
String
text
;
final
Rx
<
TextStyle
>?
textStyle
;
Rx
<
TextStyle
>?
textStyle
;
MenuEntrySwitchBase
({
required
this
.
text
,
...
...
@@ -357,6 +365,11 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
@override
List
<
mod_menu
.
PopupMenuEntry
<
T
>>
build
(
BuildContext
context
,
MenuConfig
conf
)
{
textStyle
??=
const
TextStyle
(
color:
Colors
.
black
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
)
.
obs
;
return
[
mod_menu
.
PopupMenuItem
(
padding:
EdgeInsets
.
zero
,
...
...
@@ -366,23 +379,10 @@ abstract class MenuEntrySwitchBase<T> extends MenuEntryBase<T> {
alignment:
AlignmentDirectional
.
centerStart
,
height:
conf
.
height
,
child:
Row
(
children:
[
()
{
if
(
textStyle
!=
null
)
{
final
style
=
textStyle
!;
return
Obx
(()
=>
Text
(
text
,
style:
style
.
value
,
));
}
else
{
return
Text
(
Obx
(()
=>
Text
(
text
,
style:
const
TextStyle
(
color:
Colors
.
black
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
),
);
}
}(),
style:
textStyle
!.
value
,
)),
Expanded
(
child:
Align
(
alignment:
Alignment
.
centerRight
,
...
...
@@ -485,6 +485,7 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
@override
List
<
mod_menu
.
PopupMenuEntry
<
T
>>
build
(
BuildContext
context
,
MenuConfig
conf
)
{
super
.
enabled
??=
true
.
obs
;
return
[
PopupMenuChildrenItem
(
enabled:
super
.
enabled
,
...
...
@@ -500,9 +501,7 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
Obx
(()
=>
Text
(
text
,
style:
TextStyle
(
color:
(
super
.
enabled
!=
null
?
super
.
enabled
!.
value
:
true
)
?
Colors
.
black
:
Colors
.
grey
,
color:
super
.
enabled
!.
value
?
Colors
.
black
:
Colors
.
grey
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
),
)),
...
...
@@ -511,9 +510,7 @@ class MenuEntrySubMenu<T> extends MenuEntryBase<T> {
alignment:
Alignment
.
centerRight
,
child:
Obx
(()
=>
Icon
(
Icons
.
keyboard_arrow_right
,
color:
(
super
.
enabled
!=
null
?
super
.
enabled
!.
value
:
true
)
?
conf
.
commonColor
:
Colors
.
grey
,
color:
super
.
enabled
!.
value
?
conf
.
commonColor
:
Colors
.
grey
,
)),
))
]),
...
...
@@ -537,35 +534,31 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
);
Widget
_buildChild
(
BuildContext
context
,
MenuConfig
conf
)
{
return
Obx
(()
{
bool
enabled
=
true
;
if
(
super
.
enabled
!=
null
)
{
enabled
=
super
.
enabled
!.
value
;
}
const
enabledStyle
=
TextStyle
(
color:
Colors
.
black
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
);
const
disabledStyle
=
TextStyle
(
color:
Colors
.
grey
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
);
return
TextButton
(
onPressed:
enabled
?
()
{
if
(
super
.
dismissOnClicked
&&
Navigator
.
canPop
(
context
))
{
Navigator
.
pop
(
context
);
const
enabledStyle
=
TextStyle
(
color:
Colors
.
black
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
);
const
disabledStyle
=
TextStyle
(
color:
Colors
.
grey
,
fontSize:
MenuConfig
.
fontSize
,
fontWeight:
FontWeight
.
normal
);
super
.
enabled
??=
true
.
obs
;
return
Obx
(()
=>
TextButton
(
onPressed:
super
.
enabled
!.
value
?
()
{
if
(
super
.
dismissOnClicked
&&
Navigator
.
canPop
(
context
))
{
Navigator
.
pop
(
context
);
}
proc
();
}
proc
();
}
:
null
,
child:
Container
(
alignment:
AlignmentDirectional
.
centerStart
,
constraints:
BoxConstraints
(
minHeight:
conf
.
height
),
child:
childBuilder
(
enabled
?
enabledStyle
:
disabledStyle
),
),
);
});
:
null
,
child:
Container
(
alignment:
AlignmentDirectional
.
centerStart
,
constraints:
BoxConstraints
(
minHeight:
conf
.
height
),
child:
childBuilder
(
super
.
enabled
!.
value
?
enabledStyle
:
disabledStyle
),
),
));
}
@override
...
...
@@ -573,7 +566,6 @@ class MenuEntryButton<T> extends MenuEntryBase<T> {
BuildContext
context
,
MenuConfig
conf
)
{
return
[
mod_menu
.
PopupMenuItem
(
enabled:
super
.
enabled
!=
null
?
super
.
enabled
!.
value
:
true
,
padding:
EdgeInsets
.
zero
,
height:
conf
.
height
,
child:
_buildChild
(
context
,
conf
),
...
...
flutter/lib/desktop/widgets/remote_menubar.dart
View file @
41a5d53d
...
...
@@ -611,7 +611,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
MenuEntryRadioOption
(
text:
translate
(
'Map mode'
),
value:
'map'
),
],
curOptionGetter:
()
async
{
return
await
bind
.
sessionGetKeyboardName
(
id:
widget
.
id
)
??
'legacy'
;
return
await
bind
.
sessionGetKeyboardName
(
id:
widget
.
id
);
},
optionSetter:
(
String
oldValue
,
String
newValue
)
async
{
await
bind
.
sessionSetKeyboardMode
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment