alium_sdk 1.0.1
alium_sdk: ^1.0.1 copied to clipboard
A flutter wrapper around Alium Android SDK
example/lib/main.dart
import 'package:alium_sdk/survey_parameters.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:alium_sdk/alium.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Alium.config("https://assets.aliumsurvey.com/app/cstjn/cstjn_16.json");
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
Widget build(BuildContext context) {
return MaterialApp(home: FirstScreen());
}
}
class FirstScreen extends StatefulWidget {
const FirstScreen({super.key});
@override
State<FirstScreen> createState() {
// TODO: implement createState
return _FirstScreen();
}
}
class _FirstScreen extends State<FirstScreen> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
SurveyParameters params = SurveyParametersBuilder("AI")
.addDim(1, "alium")
.addDim(2, "mumbai")
.addCustom("number", "9090909090")
.build();
Alium.triggerWithParams(params);
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
void deactivate() {
super.deactivate();
Alium.stop("home");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Running on:first screen'),
SizedBox(
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return SecondScreen();
}));
},
child: Text("Go to next screen"),
),
)
],
),
),
);
}
}
class SecondScreen extends StatefulWidget {
const SecondScreen({super.key});
@override
State<SecondScreen> createState() => _SecondScreen();
}
class _SecondScreen extends State<SecondScreen> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
Alium.trigger("second", {"dim1": "alium"});
// Alium.stop("secondscreen");
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
void deactivate() {
super.deactivate();
Alium.stop("second");
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Seond Screen"),
SizedBox(
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
onPressed: () {
// Alium.stop("secondscreen");
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return ThirdScreen();
}));
},
child: Text("Go to next screen"),
),
)
],
),
),
);
}
}
class ThirdScreen extends StatefulWidget {
const ThirdScreen({super.key});
@override
State<ThirdScreen> createState() => _ThirdScreen();
}
class _ThirdScreen extends State<ThirdScreen> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
Alium.trigger("screen4", {"dim1": "alium"});
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Third Screen"),
],
),
);
}
}