weespin_flutter 1.3.0 copy "weespin_flutter: ^1.3.0" to clipboard
weespin_flutter: ^1.3.0 copied to clipboard

PlatformAndroid

Weespin Flutter plugin. Helps you create deep links in a blink

example/lib/main.dart

import 'dart:async';

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

void main() async {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  /// Initialize Weespin client with your API key, and an optional userID.
  /// You can set userId at a later point by using [Weespin.setUserId].
  final weespin = Weespin(apiKey: 'YOUR API KEY', userId: 'user_12345');
  WeespinLink? link;
  WeespinLinkUrl? shortLink;
  Completer<void>? completer;
  StreamSubscription<Uri>? _streamSubscription;

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

  void createLink() async {
    setState(() {
      completer = Completer();
      completer!.complete(
        weespin.createLink(
          title: "My link",
          description: "Description test",
          segments: ["news", "bananas"],
          customParams: ["utm", "productId"],
        ).then((value) {
          setState(() {
            link = value;
          });
        }),
      );
    });
  }

  void editLink() async {
    setState(() {
      completer = Completer();
      completer!.complete(
        weespin.editLink(
          id: 'link_id',
          title: "My link",
          description: "Description test",
          customParams: ["utm", "productId"],
        ).then((value) {
          setState(() {
            link = value;
          });
        }),
      );
    });
  }

  void shortenLink() {
    assert(link != null);

    setState(() {
      completer = Completer();
      completer!.complete(weespin.shortenLink(
          linkId: link!.id,
          params: {"utm": 'android', "productId": '123'},
        ).then((value) {
          setState(() {
            shortLink = value;
          });
        }),
      );
    });
  }

  void sendLogEvent() async {
    setState(() {
      completer = Completer();

      completer!.complete(
        weespin.logEvent(
          eventName: "add_to_cart",
          payload: {
            "product_id": "prd_00109",
            "quantity": 2,
            "price": 49.99,
            "screen": "home",
            "platform": "android",
          },
        ),
      );
    });
  }

  void startStream() {
    _streamSubscription?.cancel();

    _streamSubscription = weespin.stream.listen(
      (Uri uri) {
        debugPrint('Path: ${uri.path}');
        debugPrint('Query Params: ${uri.queryParameters}');
      },
      onError: (error) {
        debugPrint('Stream Error: $error');
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
    _streamSubscription?.cancel();
    _streamSubscription = null;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Weespin example app')),
        body: SafeArea(
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            width: double.infinity,
            child: Column(
              children: [
                Expanded(
                  child: FutureBuilder<void>(
                    future: completer?.future,
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.none) {
                        return const SizedBox();
                      } else if (snapshot.connectionState ==
                          ConnectionState.done) {
                        return Text(
                          '${link == null ? '' : 'Link ID: ${link!.id}'}\n\n'
                          '${link == null ? '' : 'Full url: ${link!.fullUrl}'}\n\n'
                          '${shortLink == null ? '' : 'Short link: ${shortLink!.shortUrl}'}',
                        );
                      } else {
                        return const Center(child: CircularProgressIndicator());
                      }
                    },
                  ),
                ),
                FilledButton(
                  onPressed: link == null ? null : shortenLink,
                  child: const Text('Shorten link'),
                ),
                const SizedBox(height: 16.0),
                FilledButton(
                  onPressed: createLink,
                  child: const Text('Create link'),
                ),
                const SizedBox(height: 16.0),
                FilledButton(
                  onPressed: editLink,
                  child: const Text('Edit link'),
                ),
                const SizedBox(height: 16.0),
                FilledButton(
                  onPressed: sendLogEvent,
                  child: const Text('Send Log event'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
129
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Weespin Flutter plugin. Helps you create deep links in a blink

Homepage

Topics

#weespin #deeplinks #deep-links #dynamic-links

License

MIT (license)

Dependencies

app_links, flutter, play_install_referrer, shared_preferences

More

Packages that depend on weespin_flutter