Installation
Learn how to add Shake to your Flutter app.
note
Shake supports post Flutter 1.12 projects. If your project was created with the older version of Flutter, please migrate your project to the new Android APIs via official guide first.
Install
Add Shake as a dependency:
flutter pub add shake_flutter
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
dependencies:shake_flutter: ^
Now in your Dart code, you can use:
import 'package:shake_flutter/shake_flutter.dart';
Set compileSdkVersion version in the build.gradle file
Since Shake requires compileSdkVersion
29 or greater, verify that compileSdkVersion
is correctly set in the /android/app/build.gradle file:
android {compileSdkVersion 29defaultConfig {applicationId "com.shakebugs.flutter.example"minSdkVersion 24targetSdkVersion 29versionCode flutterVersionCode.toInteger()versionName flutterVersionName}}
Initialize Shake
Call Shake.start()
method in your main.dart file.
Replace your-api-client-id
and your-api-client-secret
with the actual values you have in your workspace settings:
import 'package:shake_flutter/shake_flutter.dart';void main() {WidgetsFlutterBinding.ensureInitialized();Shake.setShowFloatingReportButton(true);Shake.setInvokeShakeOnShakeDeviceEvent(true);Shake.setInvokeShakeOnScreenshot(true);Shake.start('your-api-client-id', 'your-api-client-secret');runApp(Home());}
Build and run your project by selecting Run โ Run in the menu bar. This first run will automatically add your app to your Shake dashboard based on your app bundle ID.
Conditional initialization
We recommend initializing Shake in the entry point of your app. However, depending on your app, you'll want to initialize Shake just in a specific conditions, depending on your app data. You can do it as shown in the example below when your app data is available:
import 'package:shake_flutter/shake_flutter.dart';class _MainScreenState extends State<MainScreen> {@overridevoid initState() {super.initState();if (User.isTester) {Shake.start('your-api-client-id', 'your-api-client-secret');}}
Visit your Shake dashboard
Follow the instructions there to send your first feedback with Shake and you're all set.
SDK customizations
Now that Shake SDK is in your app and you have sent the first feedback for fun, everything else is optional. As the next step, try the three most popular SDK customizations: