gits_inspector 2.0.2 copy "gits_inspector: ^2.0.2" to clipboard
gits_inspector: ^2.0.2 copied to clipboard

A simple in-app for GitsHttp inspector. Intercepts and persists all HTTP requests and responses inside your application, and provides a UI for inspecting their content.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:gits_http/gits_http.dart';

final inspector = GitsInspector(
  notificationIcon: '@mipmap/ic_launcher',
  saveInspectorToLocal: true,
  showInspectorOnShake: true,
  showNotification: true,
);

final http = GitsHttp(
  gitsInspector: inspector,
);

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    inspector.setNavigatorState(Navigator.of(context));
  }

  bool isLoading = false;
  String? error;
  Response? response;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Send HTTP call',
            ),
            if (isLoading)
              const CircularProgressIndicator()
            else if (response != null || error != null)
              Text(
                error ?? response?.body ?? '',
                style: Theme.of(context).textTheme.bodySmall,
              ),
            const SizedBox(height: 8),
            ElevatedButton(
              onPressed: () async {
                try {
                  final response = await http.get(
                    Uri.parse('https://jsonplaceholder.typicode.com/users/1'),
                  );
                  setState(() {
                    this.response = response;
                    error = null;
                  });
                } on GitsException catch (e) {
                  setState(() {
                    error = e.toGitsFailure().toString();
                  });
                } catch (e) {
                  setState(() {
                    error = e.toString();
                  });
                }
              },
              child: const Text('Send HTTP'),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
140
pub points
6%
popularity

Publisher

verified publishergits.id

A simple in-app for GitsHttp inspector. Intercepts and persists all HTTP requests and responses inside your application, and provides a UI for inspecting their content.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_local_notifications, intl, sensors_plus, share_plus, sqflite

More

Packages that depend on gits_inspector