mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-17 21:55:44 +01:00
opt.: popupmenu
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../../core/utils/ui.dart';
|
||||
import '../widget/input_field.dart';
|
||||
import '../widget/popup_menu.dart';
|
||||
import '../widget/round_rect_card.dart';
|
||||
|
||||
class ConvertPage extends StatefulWidget {
|
||||
@@ -132,28 +133,30 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
)
|
||||
],
|
||||
),
|
||||
trailing: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: _media.size.width * 0.35),
|
||||
child: buildPopuopMenu<int>(
|
||||
items: items,
|
||||
onSelected: (p0) {
|
||||
setState(() {
|
||||
_typeOptionIndex = p0;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
typeOption[_typeOptionIndex],
|
||||
textScaleFactor: 1.0,
|
||||
textAlign: TextAlign.right,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500, color: Colors.grey),
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _typeOptionIndex,
|
||||
onSelected: (p0) {
|
||||
setState(() {
|
||||
_typeOptionIndex = p0;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
typeOption[_typeOptionIndex],
|
||||
textScaleFactor: 1.0,
|
||||
textAlign: TextAlign.right,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.keyboard_arrow_down, color: Colors.grey)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -16,6 +16,7 @@ import '../../data/res/url.dart';
|
||||
import '../../data/store/docker.dart';
|
||||
import '../../locator.dart';
|
||||
import '../widget/dropdown_menu.dart';
|
||||
import '../widget/popup_menu.dart';
|
||||
import '../widget/round_rect_card.dart';
|
||||
import '../widget/two_line_text.dart';
|
||||
import '../widget/url_text.dart';
|
||||
@@ -96,14 +97,14 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
children: [
|
||||
Input(
|
||||
type: TextInputType.text,
|
||||
label: _s.dockerImage,
|
||||
label: _s.image,
|
||||
hint: 'xxx:1.1',
|
||||
controller: imageCtrl,
|
||||
),
|
||||
Input(
|
||||
type: TextInputType.text,
|
||||
controller: nameCtrl,
|
||||
label: _s.dockerContainerName,
|
||||
label: _s.containerName,
|
||||
hint: 'xxx',
|
||||
),
|
||||
Input(
|
||||
@@ -466,7 +467,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
|
||||
|
||||
Widget _buildMoreBtn(DockerPsItem dItem, bool busy) {
|
||||
final item = dItem.running ? DockerMenuItems.stop : DockerMenuItems.start;
|
||||
return buildPopuopMenu(
|
||||
return PopupMenu(
|
||||
items: [
|
||||
PopupMenuItem<DropdownBtnItem>(
|
||||
value: item,
|
||||
|
||||
@@ -154,9 +154,9 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
icon: const Icon(Icons.code),
|
||||
label: _s.convert,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.leak_add),
|
||||
label: _s.ping,
|
||||
const NavigationDestination(
|
||||
icon: Icon(Icons.leak_add),
|
||||
label: 'Ping',
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -20,6 +20,7 @@ import '../../../data/res/url.dart';
|
||||
import '../../../data/store/setting.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../widget/dropdown_menu.dart';
|
||||
import '../../widget/popup_menu.dart';
|
||||
import '../../widget/round_rect_card.dart';
|
||||
import '../../widget/url_text.dart';
|
||||
import '../docker.dart';
|
||||
@@ -258,7 +259,7 @@ class _ServerPageState extends State<ServerPage>
|
||||
}
|
||||
|
||||
Widget _buildMoreBtn(ServerPrivateInfo spi) {
|
||||
return buildPopuopMenu(
|
||||
return PopupMenu(
|
||||
items: <PopupMenuEntry>[
|
||||
...ServerTabMenuItems.firstItems.map(
|
||||
(item) => PopupMenuItem<DropdownBtnItem>(
|
||||
|
||||
@@ -21,6 +21,7 @@ import '../../data/res/ui.dart';
|
||||
import '../../data/store/setting.dart';
|
||||
import '../../locator.dart';
|
||||
import '../widget/future_widget.dart';
|
||||
import '../widget/popup_menu.dart';
|
||||
import '../widget/round_rect_card.dart';
|
||||
|
||||
class SettingPage extends StatefulWidget {
|
||||
@@ -193,8 +194,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_s.willTakEeffectImmediately,
|
||||
style: grey,
|
||||
),
|
||||
trailing: buildPopuopMenu<int>(
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _updateInterval,
|
||||
onSelected: (val) {
|
||||
setState(() {
|
||||
_updateInterval = val;
|
||||
@@ -263,8 +265,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
title: Text(
|
||||
_s.launchPage,
|
||||
),
|
||||
trailing: buildPopuopMenu<int>(
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _launchPageIdx,
|
||||
onSelected: (idx) {
|
||||
setState(() {
|
||||
_launchPageIdx = idx;
|
||||
@@ -295,8 +298,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
title: Text(
|
||||
_s.termTheme,
|
||||
),
|
||||
trailing: buildPopuopMenu<int>(
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _termThemeIdx,
|
||||
onSelected: (idx) {
|
||||
setState(() {
|
||||
_termThemeIdx = idx;
|
||||
@@ -326,8 +330,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_s.maxRetryCount,
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
trailing: buildPopuopMenu<int>(
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _maxRetryCount,
|
||||
onSelected: (val) {
|
||||
setState(() {
|
||||
_maxRetryCount = val;
|
||||
@@ -356,8 +361,9 @@ class _SettingPageState extends State<SettingPage> {
|
||||
title: Text(
|
||||
_s.themeMode,
|
||||
),
|
||||
trailing: buildPopuopMenu<int>(
|
||||
trailing: PopupMenu<int>(
|
||||
items: items,
|
||||
initialValue: _nightMode,
|
||||
onSelected: (idx) {
|
||||
_nightMode = idx;
|
||||
_setting.themeMode.put(_nightMode);
|
||||
|
||||
31
lib/view/widget/popup_menu.dart
Normal file
31
lib/view/widget/popup_menu.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
|
||||
class PopupMenu<T> extends StatelessWidget {
|
||||
final List<PopupMenuEntry<T>> items;
|
||||
final void Function(T) onSelected;
|
||||
final Widget child;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final T? initialValue;
|
||||
|
||||
const PopupMenu({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.onSelected,
|
||||
this.child = popMenuChild,
|
||||
this.padding = const EdgeInsets.all(7),
|
||||
this.initialValue,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopupMenuButton<T>(
|
||||
itemBuilder: (_) => items,
|
||||
onSelected: onSelected,
|
||||
initialValue: initialValue,
|
||||
padding: padding,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user