mirror of
https://github.com/foss42/apidash.git
synced 2025-08-26 06:11:06 +08:00
fix: review changes
This commit is contained in:
127
lib/widgets/card_sidebar_environment.dart
Normal file
127
lib/widgets/card_sidebar_environment.dart
Normal file
@ -0,0 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import 'menus.dart' show ItemCardMenu;
|
||||
|
||||
class SidebarEnvironmentCard extends StatelessWidget {
|
||||
const SidebarEnvironmentCard({
|
||||
super.key,
|
||||
required this.id,
|
||||
this.isGlobal = false,
|
||||
this.isActive = false,
|
||||
this.name,
|
||||
this.selectedId,
|
||||
this.editRequestId,
|
||||
this.setActive,
|
||||
this.onTap,
|
||||
this.onDoubleTap,
|
||||
this.onSecondaryTap,
|
||||
this.onChangedNameEditor,
|
||||
this.focusNode,
|
||||
this.onTapOutsideNameEditor,
|
||||
this.onMenuSelected,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final bool isGlobal;
|
||||
final bool isActive;
|
||||
final String? name;
|
||||
final String? selectedId;
|
||||
final String? editRequestId;
|
||||
final void Function(bool?)? setActive;
|
||||
final void Function()? onTap;
|
||||
final void Function()? onDoubleTap;
|
||||
final void Function()? onSecondaryTap;
|
||||
final Function(String)? onChangedNameEditor;
|
||||
final FocusNode? focusNode;
|
||||
final Function()? onTapOutsideNameEditor;
|
||||
final Function(ItemMenuOption)? onMenuSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final Color color =
|
||||
isGlobal ? colorScheme.secondaryContainer : colorScheme.surface;
|
||||
final Color colorVariant = colorScheme.surfaceVariant.withOpacity(0.5);
|
||||
final Color surfaceTint = colorScheme.primary;
|
||||
bool isSelected = selectedId == id;
|
||||
bool inEditMode = editRequestId == id;
|
||||
String nm = getEnvironmentTitle(name);
|
||||
return Tooltip(
|
||||
message: nm,
|
||||
triggerMode: TooltipTriggerMode.manual,
|
||||
waitDuration: const Duration(seconds: 1),
|
||||
child: Card(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: kBorderRadius8,
|
||||
),
|
||||
elevation: isSelected ? 1 : 0,
|
||||
surfaceTintColor: isSelected ? surfaceTint : null,
|
||||
color: isSelected && !isGlobal
|
||||
? colorScheme.brightness == Brightness.dark
|
||||
? colorVariant
|
||||
: color
|
||||
: color,
|
||||
margin: EdgeInsets.zero,
|
||||
child: InkWell(
|
||||
borderRadius: kBorderRadius8,
|
||||
hoverColor: colorVariant,
|
||||
focusColor: colorVariant.withOpacity(0.5),
|
||||
onTap: inEditMode ? null : onTap,
|
||||
onSecondaryTap: onSecondaryTap,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 6,
|
||||
right: isSelected ? 6 : 10,
|
||||
top: 5,
|
||||
bottom: 5,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 20,
|
||||
child: Row(
|
||||
children: [
|
||||
kHSpacer4,
|
||||
Expanded(
|
||||
child: inEditMode
|
||||
? TextFormField(
|
||||
key: ValueKey("$id-name"),
|
||||
initialValue: name,
|
||||
focusNode: focusNode,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
onTapOutside: (_) {
|
||||
onTapOutsideNameEditor?.call();
|
||||
},
|
||||
onFieldSubmitted: (value) {
|
||||
onTapOutsideNameEditor?.call();
|
||||
},
|
||||
onChanged: onChangedNameEditor,
|
||||
decoration: const InputDecoration(
|
||||
isCollapsed: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
nm,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: isSelected && !inEditMode && !isGlobal,
|
||||
child: SizedBox(
|
||||
width: 28,
|
||||
child: ItemCardMenu(
|
||||
onSelected: onMenuSelected,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user