Skip to content

Commit b1e7cfa

Browse files
committed
Update editor_request.dart
1 parent 304fb3c commit b1e7cfa

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

lib/screens/home_page/editor_pane/editor_request.dart

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
import 'package:apidash/providers/collection_providers.dart';
24
import 'package:apidash/consts.dart';
35
import 'details_card/details_card.dart';
46
import 'url_card.dart';
@@ -10,6 +12,7 @@ class RequestEditor extends StatelessWidget {
1012
Widget build(BuildContext context) {
1113
return const Column(
1214
children: [
15+
RequestEditorTopBar(),
1316
EditorPaneRequestURLCard(),
1417
kVSpacer10,
1518
Expanded(
@@ -19,3 +22,91 @@ class RequestEditor extends StatelessWidget {
1922
);
2023
}
2124
}
25+
26+
class RequestEditorTopBar extends ConsumerWidget {
27+
const RequestEditorTopBar({super.key});
28+
29+
@override
30+
Widget build(BuildContext context, WidgetRef ref) {
31+
final id = ref.watch(selectedIdStateProvider);
32+
final name =
33+
ref.watch(selectedRequestModelProvider.select((value) => value?.name));
34+
return Padding(
35+
padding: const EdgeInsets.only(
36+
left: 12.0,
37+
top: 4.0,
38+
right: 8.0,
39+
bottom: 4.0,
40+
),
41+
child: Row(
42+
children: [
43+
Expanded(
44+
child: Text(
45+
name ?? "",
46+
style: Theme.of(context).textTheme.bodyMedium,
47+
overflow: TextOverflow.ellipsis,
48+
maxLines: 1,
49+
),
50+
),
51+
const SizedBox(
52+
width: 6,
53+
),
54+
SizedBox(
55+
width: 90,
56+
height: 24,
57+
child: FilledButton.tonalIcon(
58+
style: const ButtonStyle(
59+
padding: MaterialStatePropertyAll(EdgeInsets.zero),
60+
),
61+
onPressed: () {
62+
showDialog(
63+
context: context,
64+
builder: (context) {
65+
final controller =
66+
TextEditingController(text: name ?? "");
67+
controller.selection = TextSelection(
68+
baseOffset: 0, extentOffset: controller.text.length);
69+
return AlertDialog(
70+
title: const Text('Rename Request'),
71+
content: TextField(
72+
autofocus: true,
73+
controller: controller,
74+
decoration:
75+
const InputDecoration(hintText: "Enter new name"),
76+
),
77+
actions: <Widget>[
78+
OutlinedButton(
79+
onPressed: () {
80+
Navigator.pop(context);
81+
},
82+
child: const Text('CANCEL')),
83+
FilledButton(
84+
onPressed: () {
85+
final val = controller.text.trim();
86+
ref
87+
.read(collectionStateNotifierProvider
88+
.notifier)
89+
.update(id!, name: val);
90+
Navigator.pop(context);
91+
controller.dispose();
92+
},
93+
child: const Text('OK')),
94+
],
95+
);
96+
});
97+
},
98+
icon: const Icon(
99+
Icons.edit,
100+
size: 12,
101+
),
102+
label: Text(
103+
"Rename",
104+
style: Theme.of(context).textTheme.bodySmall,
105+
),
106+
),
107+
)
108+
],
109+
),
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)