mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
Button state provider and UI update
This commit is contained in:
@ -5,16 +5,15 @@ import '../../utils/utils.dart';
|
|||||||
import '../styles.dart';
|
import '../styles.dart';
|
||||||
import '../../consts.dart';
|
import '../../consts.dart';
|
||||||
|
|
||||||
class EditorPaneRequestURLCard extends ConsumerStatefulWidget {
|
class EditorPaneRequestURLCard extends StatefulWidget {
|
||||||
const EditorPaneRequestURLCard({super.key});
|
const EditorPaneRequestURLCard({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<EditorPaneRequestURLCard> createState() =>
|
State<EditorPaneRequestURLCard> createState() =>
|
||||||
_EditorPaneRequestURLCardState();
|
_EditorPaneRequestURLCardState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EditorPaneRequestURLCardState
|
class _EditorPaneRequestURLCardState extends State<EditorPaneRequestURLCard> {
|
||||||
extends ConsumerState<EditorPaneRequestURLCard> {
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -22,7 +21,6 @@ class _EditorPaneRequestURLCardState
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final activeId = ref.watch(activeIdStateProvider);
|
|
||||||
return Card(
|
return Card(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
@ -37,38 +35,20 @@ class _EditorPaneRequestURLCardState
|
|||||||
horizontal: 20,
|
horizontal: 20,
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: const [
|
||||||
const DropdownButtonHTTPMethod(),
|
DropdownButtonHTTPMethod(),
|
||||||
const SizedBox(
|
SizedBox(
|
||||||
width: 20,
|
width: 20,
|
||||||
),
|
),
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: URLTextField(),
|
child: URLTextField(),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
SizedBox(
|
||||||
width: 20,
|
width: 20,
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 36,
|
height: 36,
|
||||||
child: FilledButton(
|
child: SendRequestButton(),
|
||||||
onPressed: () async {
|
|
||||||
ref
|
|
||||||
.read(collectionStateNotifierProvider.notifier)
|
|
||||||
.sendRequest(activeId!);
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
children: const [
|
|
||||||
Text(
|
|
||||||
"Send",
|
|
||||||
style: textStyleButton,
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 10,
|
|
||||||
),
|
|
||||||
Icon(size: 16, Icons.send),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -172,3 +152,65 @@ class _URLTextFieldState extends ConsumerState<URLTextField> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SendRequestButton extends ConsumerStatefulWidget {
|
||||||
|
const SendRequestButton({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<SendRequestButton> createState() => _SendRequestButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SendRequestButtonState extends ConsumerState<SendRequestButton> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final activeId = ref.watch(activeIdStateProvider);
|
||||||
|
final sentRequestId = ref.watch(sentRequestIdStateProvider);
|
||||||
|
bool disable = sentRequestId != null;
|
||||||
|
return FilledButton(
|
||||||
|
onPressed: disable
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
ref
|
||||||
|
.read(sentRequestIdStateProvider.notifier)
|
||||||
|
.update((state) => activeId);
|
||||||
|
await Future.delayed(
|
||||||
|
const Duration(seconds: 5),
|
||||||
|
() {
|
||||||
|
ref
|
||||||
|
.read(collectionStateNotifierProvider.notifier)
|
||||||
|
.sendRequest(activeId!);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ref
|
||||||
|
.read(sentRequestIdStateProvider.notifier)
|
||||||
|
.update((state) => null);
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
disable
|
||||||
|
? (activeId == sentRequestId ? "Sending.." : "Busy")
|
||||||
|
: "Send",
|
||||||
|
style: textStyleButton,
|
||||||
|
),
|
||||||
|
if (!disable)
|
||||||
|
const SizedBox(
|
||||||
|
width: 10,
|
||||||
|
),
|
||||||
|
if (!disable)
|
||||||
|
const Icon(
|
||||||
|
size: 16,
|
||||||
|
Icons.send,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ import '../consts.dart';
|
|||||||
const _uuid = Uuid();
|
const _uuid = Uuid();
|
||||||
|
|
||||||
final activeIdStateProvider = StateProvider<String?>((ref) => null);
|
final activeIdStateProvider = StateProvider<String?>((ref) => null);
|
||||||
|
final sentRequestIdStateProvider = StateProvider<String?>((ref) => null);
|
||||||
|
|
||||||
final StateNotifierProvider<CollectionStateNotifier, List<RequestModel>>
|
final StateNotifierProvider<CollectionStateNotifier, List<RequestModel>>
|
||||||
collectionStateNotifierProvider =
|
collectionStateNotifierProvider =
|
||||||
|
Reference in New Issue
Block a user