mirror of
https://github.com/foss42/apidash.git
synced 2025-06-30 12:57:27 +08:00
feat: Tab indicators for request params, headers, body
This commit is contained in:
@ -18,15 +18,20 @@ class _EditRequestPaneState extends ConsumerState<EditRequestPane> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final activeId = ref.watch(activeIdStateProvider);
|
final activeId = ref.watch(activeIdStateProvider);
|
||||||
final codePaneVisible = ref.watch(codePaneVisibleStateProvider);
|
final codePaneVisible = ref.watch(codePaneVisibleStateProvider);
|
||||||
var index = ref
|
final tabIndex = ref.watch(
|
||||||
.read(collectionStateNotifierProvider.notifier)
|
activeRequestModelProvider.select((value) => value?.requestTabIndex));
|
||||||
.getRequestModel(activeId!)
|
|
||||||
.requestTabIndex;
|
final headerLength = ref.watch(activeRequestModelProvider
|
||||||
|
.select((value) => value?.requestHeaders?.length));
|
||||||
|
final paramLength = ref.watch(activeRequestModelProvider
|
||||||
|
.select((value) => value?.requestParams?.length));
|
||||||
|
final bodyLength = ref.watch(activeRequestModelProvider
|
||||||
|
.select((value) => value?.requestBody?.length));
|
||||||
|
|
||||||
return RequestPane(
|
return RequestPane(
|
||||||
activeId: activeId,
|
activeId: activeId,
|
||||||
codePaneVisible: codePaneVisible,
|
codePaneVisible: codePaneVisible,
|
||||||
tabIndex: index,
|
tabIndex: tabIndex,
|
||||||
onPressedCodeButton: () {
|
onPressedCodeButton: () {
|
||||||
ref
|
ref
|
||||||
.read(codePaneVisibleStateProvider.notifier)
|
.read(codePaneVisibleStateProvider.notifier)
|
||||||
@ -35,8 +40,13 @@ class _EditRequestPaneState extends ConsumerState<EditRequestPane> {
|
|||||||
onTapTabBar: (index) {
|
onTapTabBar: (index) {
|
||||||
ref
|
ref
|
||||||
.read(collectionStateNotifierProvider.notifier)
|
.read(collectionStateNotifierProvider.notifier)
|
||||||
.update(activeId, requestTabIndex: index);
|
.update(activeId!, requestTabIndex: index);
|
||||||
},
|
},
|
||||||
|
showIndicators: [
|
||||||
|
paramLength != null && paramLength > 0,
|
||||||
|
headerLength != null && headerLength > 0,
|
||||||
|
bodyLength != null && bodyLength > 0,
|
||||||
|
],
|
||||||
children: const [
|
children: const [
|
||||||
EditRequestURLParams(),
|
EditRequestURLParams(),
|
||||||
EditRequestHeaders(),
|
EditRequestHeaders(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'tabs.dart';
|
||||||
|
|
||||||
class RequestPane extends StatefulWidget {
|
class RequestPane extends StatefulWidget {
|
||||||
const RequestPane({
|
const RequestPane({
|
||||||
@ -10,6 +11,7 @@ class RequestPane extends StatefulWidget {
|
|||||||
this.onPressedCodeButton,
|
this.onPressedCodeButton,
|
||||||
this.onTapTabBar,
|
this.onTapTabBar,
|
||||||
required this.children,
|
required this.children,
|
||||||
|
this.showIndicators = const [false, false, false],
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? activeId;
|
final String? activeId;
|
||||||
@ -18,6 +20,7 @@ class RequestPane extends StatefulWidget {
|
|||||||
final void Function()? onPressedCodeButton;
|
final void Function()? onPressedCodeButton;
|
||||||
final void Function(int)? onTapTabBar;
|
final void Function(int)? onTapTabBar;
|
||||||
final List<Widget> children;
|
final List<Widget> children;
|
||||||
|
final List<bool> showIndicators;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<RequestPane> createState() => _RequestPaneState();
|
State<RequestPane> createState() => _RequestPaneState();
|
||||||
@ -77,40 +80,18 @@ class _RequestPaneState extends State<RequestPane>
|
|||||||
controller: _controller,
|
controller: _controller,
|
||||||
overlayColor: kColorTransparentState,
|
overlayColor: kColorTransparentState,
|
||||||
onTap: widget.onTapTabBar,
|
onTap: widget.onTapTabBar,
|
||||||
tabs: const [
|
tabs: [
|
||||||
SizedBox(
|
TabLabel(
|
||||||
height: kTabHeight,
|
text: 'URL Params',
|
||||||
child: Center(
|
showIndicator: widget.showIndicators[0],
|
||||||
child: Text(
|
|
||||||
'URL Params',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
softWrap: false,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(
|
TabLabel(
|
||||||
height: kTabHeight,
|
text: 'Headers',
|
||||||
child: Center(
|
showIndicator: widget.showIndicators[1],
|
||||||
child: Text(
|
|
||||||
'Headers',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(
|
TabLabel(
|
||||||
height: kTabHeight,
|
text: 'Body',
|
||||||
child: Center(
|
showIndicator: widget.showIndicators[2],
|
||||||
child: Text(
|
|
||||||
'Body',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.fade,
|
|
||||||
style: kTextStyleButton,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
39
lib/widgets/tabs.dart
Normal file
39
lib/widgets/tabs.dart
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
|
||||||
|
class TabLabel extends StatelessWidget {
|
||||||
|
const TabLabel({super.key, required this.text, this.showIndicator = false});
|
||||||
|
final String text;
|
||||||
|
final bool showIndicator;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
height: kTabHeight,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
softWrap: false,
|
||||||
|
style: kTextStyleButton,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (showIndicator)
|
||||||
|
const Align(
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(top: 6),
|
||||||
|
child: Icon(
|
||||||
|
Icons.circle,
|
||||||
|
size: 6,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -17,3 +17,4 @@ export 'response_widgets.dart';
|
|||||||
export 'snackbars.dart';
|
export 'snackbars.dart';
|
||||||
export 'markdown.dart';
|
export 'markdown.dart';
|
||||||
export 'uint8_audio_player.dart';
|
export 'uint8_audio_player.dart';
|
||||||
|
export 'tabs.dart';
|
||||||
|
Reference in New Issue
Block a user