flutter_flipperkit 0.0.29 flutter_flipperkit: ^0.0.29 copied to clipboard
Flipper (Extensible mobile app debugger) for flutter.
import 'package:flutter/material.dart';
import 'package:flutter_flipperkit/flutter_flipperkit.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uuid/uuid.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
FlipperClient flipperClient = FlipperClient.getDefault();
flipperClient.addPlugin(new FlipperNetworkPlugin());
flipperClient.addPlugin(new FlipperSharedPreferencesPlugin());
// flipperClient.addPlugin(new FlipperDatabaseBrowserPlugin());
flipperClient.addPlugin(new FlipperReduxInspectorPlugin());
flipperClient.start();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void _testNetwork() {
FlipperNetworkPlugin flipperNetworkPlugin =
FlipperClient.getDefault().getPlugin("Network") as FlipperNetworkPlugin;
String uniqueId = new Uuid().v4();
RequestInfo requestInfo = new RequestInfo(
requestId: uniqueId,
timeStamp: new DateTime.now().millisecondsSinceEpoch,
uri: 'https://example.com/account/login',
headers: new Map()..putIfAbsent("Content-Type", () => "application/json"),
method: 'POST',
body: new Map()
..putIfAbsent("username", () => "example")
..putIfAbsent("password", () => "123456"),
);
flipperNetworkPlugin.reportRequest(requestInfo);
ResponseInfo responseInfo = new ResponseInfo(
requestId: uniqueId,
timeStamp: new DateTime.now().millisecondsSinceEpoch,
statusCode: 200,
headers: new Map()..putIfAbsent("Content-Type", () => "application/json"),
body: new Map()
..putIfAbsent("username", () => "lijy91")
..putIfAbsent("age", () => 28)
..putIfAbsent("name", () => "LiJianying"),
);
flipperNetworkPlugin.reportResponse(responseInfo);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
ListTile(
title: Text("Preferences"),
onTap: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
int counter = (prefs.getInt('counter') ?? 0) + 1;
await prefs.setInt('counter', counter);
},
),
ListTile(
title: Text("Network"),
onTap: this._testNetwork,
),
ListTile(
title: Text("ReduxInspector"),
onTap: () {
FlipperReduxInspectorPlugin flipperReduxInspectorPlugin =
FlipperClient.getDefault()
.getPlugin("flipper-plugin-reduxinspector")
as FlipperReduxInspectorPlugin;
ActionInfo actionInfo = ActionInfo(
uniqueId: new Uuid().v4(),
actionType: 'LoginSuccess',
timeStamp: new DateTime.now().millisecondsSinceEpoch,
payload: new Map()
..putIfAbsent("username", () => "lijy91@foxmail.com")
..putIfAbsent("password", () => "123456"),
nextState: new Map()
..putIfAbsent("user", () => {"name": "LiJianying"}),
);
flipperReduxInspectorPlugin.report(actionInfo);
},
),
],
),
),
);
}
}