mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
Refactored collection state management to handle API type changes and AI request models. Updated widgets and tests to support nullable HTTP methods and AI request models, and improved response body rendering for AI responses.
144 lines
4.8 KiB
Dart
144 lines
4.8 KiB
Dart
import 'package:apidash_core/apidash_core.dart';
|
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:apidash/consts.dart';
|
|
import 'package:apidash/utils/utils.dart';
|
|
import 'menu_item_card.dart';
|
|
import 'texts.dart';
|
|
|
|
class SidebarRequestCard extends StatelessWidget {
|
|
const SidebarRequestCard({
|
|
super.key,
|
|
required this.id,
|
|
required this.apiType,
|
|
this.method,
|
|
this.name,
|
|
this.url,
|
|
this.selectedId,
|
|
this.editRequestId,
|
|
this.onTap,
|
|
this.onDoubleTap,
|
|
this.onSecondaryTap,
|
|
this.onChangedNameEditor,
|
|
// this.controller,
|
|
this.focusNode,
|
|
this.onTapOutsideNameEditor,
|
|
this.onMenuSelected,
|
|
});
|
|
|
|
final String id;
|
|
final APIType apiType;
|
|
final String? name;
|
|
final String? url;
|
|
final HTTPVerb? method;
|
|
final String? selectedId;
|
|
final String? editRequestId;
|
|
final void Function()? onTap;
|
|
final void Function()? onDoubleTap;
|
|
final void Function()? onSecondaryTap;
|
|
final Function(String)? onChangedNameEditor;
|
|
// final TextEditingController? controller;
|
|
final FocusNode? focusNode;
|
|
final Function()? onTapOutsideNameEditor;
|
|
final Function(ItemMenuOption)? onMenuSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Color color = Theme.of(context).colorScheme.surface;
|
|
final Color colorVariant = Theme.of(context).colorScheme.surfaceContainer;
|
|
final Color surfaceTint = Theme.of(context).colorScheme.primary;
|
|
bool isSelected = selectedId == id;
|
|
bool inEditMode = editRequestId == id;
|
|
String nm = (name != null && name!.trim().isNotEmpty)
|
|
? name!
|
|
: getRequestTitleFromUrl(url);
|
|
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
|
|
? Theme.of(context).colorScheme.brightness == Brightness.dark
|
|
? colorVariant
|
|
: color
|
|
: color,
|
|
margin: EdgeInsets.zero,
|
|
child: InkWell(
|
|
borderRadius: kBorderRadius8,
|
|
hoverColor: colorVariant,
|
|
focusColor: colorVariant,
|
|
onTap: inEditMode ? null : onTap,
|
|
// onDoubleTap: inEditMode ? null : onDoubleTap,
|
|
onSecondaryTapUp: (details) {
|
|
onSecondaryTap?.call();
|
|
showItemCardMenu(context, details, onMenuSelected);
|
|
},
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
left: 6,
|
|
right: isSelected ? 6 : 10,
|
|
top: 5,
|
|
bottom: 5,
|
|
),
|
|
child: SizedBox(
|
|
height: 20,
|
|
child: Row(
|
|
children: [
|
|
SidebarRequestCardTextBox(
|
|
apiType: apiType,
|
|
method: method,
|
|
),
|
|
kHSpacer4,
|
|
Expanded(
|
|
child: inEditMode
|
|
? TextFormField(
|
|
key: ValueKey("$id-name"),
|
|
initialValue: name,
|
|
// controller: controller,
|
|
focusNode: focusNode,
|
|
//autofocus: true,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
onTapOutside: (_) {
|
|
FocusScope.of(context).unfocus();
|
|
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,
|
|
child: SizedBox(
|
|
width: 28,
|
|
child: ItemCardMenu(
|
|
onSelected: onMenuSelected,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|