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

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;

  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 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",
        },
      ));
    });
  }

  @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'),
                ),
                FilledButton(
                  onPressed: sendLogEvent,
                  child: const Text('Send Log event'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
87
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage

Topics

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

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on weespin_flutter