flutter_smartlook 4.0.8 copy "flutter_smartlook: ^4.0.8" to clipboard
flutter_smartlook: ^4.0.8 copied to clipboard

outdated

Smartlook SDK wrapper for Flutter. Analyze user behavior in ways never possible before.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_smartlook/flutter_smartlook.dart';
import 'package:flutter_smartlook_example/test_screen.dart';
import 'package:flutter_smartlook_example/timer_widget.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() => runApp(MyApp());

class CustomIntegrationListener implements IntegrationListener {
  @override
  void onSessionReady(String? dashboardSessionUrl) {
    debugPrint('---------');
    debugPrint('DashboardUrl:');
    debugPrint(dashboardSessionUrl);
  }

  @override
  void onVisitorReady(String? dashboardVisitorUrl) {
    debugPrint('---------');
    debugPrint('DashboardVisitorUrl:');
    debugPrint(dashboardVisitorUrl);
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final Smartlook smartlook = Smartlook.instance;
  bool isSet = false;

  @override
  void initState() {
    super.initState();
    initSmartlook();
  }

  Future<void> initSmartlook() async {
    await smartlook.log.enableLogging();
    //TODO add your project key
    await smartlook.preferences
        .setProjectKey('');
    await smartlook.start();
    smartlook.registerIntegrationListener(CustomIntegrationListener());
    await smartlook.preferences.setWebViewEnabled(true);
    setState(() {
      isSet = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [SmartlookObserver()],
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: !isSet
              ? const Center(child: CircularProgressIndicator())
              : Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    const Spacer(),
                    const TimerWidget(),
                    const SizedBox(height: 15.0),
                    FutureBuilder<RecordingStatus>(
                        future: smartlook.state.getRecordingStatus(),
                        builder: (context, snapshot) {
                          if (snapshot.connectionState ==
                              ConnectionState.waiting) {
                            return const CircularProgressIndicator();
                          }
                          if (snapshot.data == null ||
                              snapshot.data != RecordingStatus.recording) {
                            return ElevatedButton(
                              onPressed: () async {
                                await smartlook.start();
                                setState(() {});
                              },
                              child: const Text('Start recording'),
                            );
                          }
                          return ElevatedButton(
                            onPressed: () async {
                              await smartlook.stop();
                              setState(() {});
                            },
                            child: const Text('Stop recording'),
                          );
                        }),
                    const SizedBox(height: 15),
                    ElevatedButton(
                      onPressed: () {
                        final Properties properties = Properties();
                        properties.putString('testKey', value: 'testValue');
                        smartlook.trackEvent('test_event',
                            properties: properties);
                      },
                      child: const Text('Track event'),
                    ),
                    const SizedBox(height: 15.0),
                    Builder(builder: (context) {
                      return ElevatedButton(
                        onPressed: () async {
                          smartlook.trackNavigationEnter('testscreen');
                          await Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => const TestScreen()),
                          );
                          smartlook.trackNavigationExit('testscreen');
                        },
                        child: const Text('Navigate to TestScreen'),
                      );
                    }),
                    const Spacer(),
                    const SizedBox(
                      height: 180,
                      child: WebView(
                        initialUrl: 'https://flutter.dev',
                        javascriptMode: JavascriptMode.unrestricted,
                      ),
                    )
                  ],
                ),
        ),
      ),
    );
  }
}
46
likes
0
points
30k
downloads

Publisher

verified publishersmartlook.com

Weekly Downloads

Smartlook SDK wrapper for Flutter. Analyze user behavior in ways never possible before.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_smartlook