Last active
January 27, 2021 10:41
-
-
Save opsb/0ce699ea3b7529a49e89c6c091ceb70d to your computer and use it in GitHub Desktop.
AppSpector flutter widget that supports hot restart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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