weespin_flutter 1.1.0
weespin_flutter: ^1.1.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/cupertino.dart';
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> {
final weespin = Weespin(apiKey: 'YOUR API KEY');
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;
});
})
);
});
}
@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'),
),
],
),
),
),
),
);
}
}