dio_mock_interceptor 2.1.0 copy "dio_mock_interceptor: ^2.1.0" to clipboard
dio_mock_interceptor: ^2.1.0 copied to clipboard

This widget help you to mock backend responses in flutter project.

example/lib/main.dart

import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:dio_mock_interceptor/dio_mock_interceptor.dart';

void main() async {
  Dio dio = Dio(BaseOptions());

  dio.interceptors.add(MockInterceptor());

  Response response =
      await dio.post("/api/basic/data"); // the same path as common.json
  String json = response.data;
  if (json.isEmpty) {
    throw Exception('response is empty');
  }

  Map<String, dynamic> data = jsonDecode(json);
  bool isSuccess = data['success'] as bool;
  print(isSuccess); // true
  Map<String, dynamic> result = data['result'];
  print(result['test']); //test
}
6
likes
140
pub points
69%
popularity

Publisher

verified publisheryong-xin.tech

This widget help you to mock backend responses in flutter project.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dio, flutter, template_expressions

More

Packages that depend on dio_mock_interceptor