Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix network copy bug #5476

Merged
merged 5 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the request atab copy buttons behave better with the updating data.
  • Loading branch information
CoderDake committed Mar 22, 2023
commit 1986fed7c07067cfc9f8327ee5e653fd3ea322b0
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ class NetworkRequestInspector extends StatelessWidget {
if (data.requestBody != null)
_buildTab(
tabName: NetworkRequestInspector._requestTabTitle,
trailing: HttpViewCopyButton(data,(data) => data.requestBody),
trailing: HttpViewTrailingCopyButton(
data,
(data) => data.requestBody,
),
),
if (data.responseBody != null)
_buildTab( // These need a value listenable builder!!!!!!!!!! yuck
_buildTab(
tabName: NetworkRequestInspector._responseTabTitle,
trailing: HttpViewCopyButton(data,(data) => data.responseBody),
trailing: HttpViewTrailingCopyButton(
data,
(data) => data.responseBody,
),
),
if (data.hasCookies)
_buildTab(tabName: NetworkRequestInspector._cookiesTabTitle),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,36 @@ class HttpRequestView extends StatelessWidget {
);
}
}
class HttpViewCopyButton extends StatelessWidget {
HttpViewCopyButton(this.data, this.dataSelector);

/// A button for copying [DartIOHttpRequestData] contents.
///
/// If there is no content to copy, the button will not show. The copy contents
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hiding the button, we should just disable the onPressed handler. This will keep the UI consistent and not confuse users why sometimes the button is there and sometimes it is not. This is pretty standard across the rest of DevTools. For example, we don't remove a pause button when we are already paused, we just disable the onPressed handler so it shows up as disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM
Issue created: #5519

/// will update as the request's data is updated.
class HttpViewTrailingCopyButton extends StatelessWidget {
const HttpViewTrailingCopyButton(this.data, this.dataSelector);
final DartIOHttpRequestData data;
final String? Function(DartIOHttpRequestData) dataSelector;
final String? Function(DartIOHttpRequestData) dataSelector;
@override
CoderDake marked this conversation as resolved.
Show resolved Hide resolved
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: data.requestUpdatedNotifier,
builder: (context, __, ___) {
final dataToCopy = dataSelector(data);
if(dataToCopy == null || dataToCopy == '') return Container();
final isLoading = data.isFetchingFullData;
if (dataToCopy == null || dataToCopy == '' || isLoading)
CoderDake marked this conversation as resolved.
Show resolved Hide resolved
return Container();
CoderDake marked this conversation as resolved.
Show resolved Hide resolved

return Align(
alignment: Alignment.centerRight,
child: CopyToClipboardControl(
dataProvider: () => dataToCopy,
),
);
alignment: Alignment.centerRight,
child: CopyToClipboardControl(
dataProvider: () => dataToCopy,
),
);
},
);
}
}

class HttpResponseView extends StatelessWidget {
const HttpResponseView(this.data);

Expand Down