foss42 / apidash

API Dash is a beautiful open-source cross-platform API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. It is supported for macOS, Windows, Linux, Android & iOS. A lightweight alternative to postman/insomnia.
https://apidash.dev
Apache License 2.0
1.66k stars 317 forks source link

Ability to clear current response #310

Closed animator closed 7 months ago

animator commented 7 months ago

Tell us about the task you want to perform and are unable to do so because the feature is not available There should be a small recycle bin or clear button in the response section to clear the current response.

mdmohsin7 commented 7 months ago

Hi @animator I have implemented this functionality (have attached a demo video of it). Below is the implementation of the ClearResponseButton. Unlike all the other buttons, it extends ConsumerWidget instead of Stateless/Stateful Widget. Before I open a PR, I wanted to confirm whether this is allowed or not. Thanks in advance

class ClearResponseButton extends ConsumerWidget {
  const ClearResponseButton({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var sm = ScaffoldMessenger.of(context);
    return SizedBox(
      child: TextButton(
        style: TextButton.styleFrom(minimumSize: const Size(40, 40)),
        onPressed: () {
          final selectedId = ref.watch(selectedIdStateProvider);
          ref
              .read(collectionStateNotifierProvider.notifier)
              .clearResponse(selectedId!);
          sm.hideCurrentSnackBar();
          sm.showSnackBar(
            SnackBar(
              content: const Text('Response cleared'),
              action: SnackBarAction(
                label: 'Undo',
                onPressed: () {},
              ),
            ),
          );
        },
        child: const Icon(
          Icons.delete,
          size: 20,
        ),
      ),
    );
  }
}

https://github.com/foss42/apidash/assets/59914433/63de8050-1c73-478a-b97a-8580e9aa97c8

ashitaprasad commented 7 months ago

@mdmohsin7 Please open a PR for review.