Skip to content

Instantly share code, notes, and snippets.

@opsb
Last active January 27, 2021 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opsb/0ce699ea3b7529a49e89c6c091ceb70d to your computer and use it in GitHub Desktop.
Save opsb/0ce699ea3b7529a49e89c6c091ceb70d to your computer and use it in GitHub Desktop.
AppSpector flutter widget that supports hot restart
import 'package:appspector/appspector.dart';
import 'package:flutter/material.dart';
class AppSpectorWidget extends StatefulWidget {
final String iosApiKey;
final String androidApiKey;
final Widget child;
AppSpectorWidget(
{@required this.iosApiKey,
@required this.androidApiKey,
@required this.child});
@override
_AppSpectorWidgetState createState() => _AppSpectorWidgetState();
}
class _AppSpectorWidgetState extends State<AppSpectorWidget> {
@override
void initState() {
super.initState();
_runAppSpector();
}
@override
Widget build(BuildContext context) {
return widget.child;
}
void _runAppSpector() {
final config = Config()
..iosApiKey = widget.iosApiKey
..androidApiKey = widget.androidApiKey;
AppSpectorPlugin.run(config).then((_) {
// the second call is necessary for hot restart to work, no idea why...
AppSpectorPlugin.run(config);
});
}
}
import 'app_spector_widget.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
AppSpectorWidget(
iosApiKey: "YOUR_APP_SPECTOR_IOS_KEY",
androidApiKey: "YOUR_APP_SPECTOR_ANDROID_KEY",
child: CedarWidget<Env, Model, Msg>(app: Simon()),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment