instadiv 0.0.4
instadiv: ^0.0.4 copied to clipboard
InstaDiv is a SaaS which helps in boosting in-app engagment using server-driven pop-ups, Picture-in-Picture stories, banners & carousels.
example/lib/main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:instadiv/instadiv.dart';
import 'package:instadiv/widget/insta_view.dart';
import 'package:instadiv/widget/pip/insta_screen.dart';
import 'package:instadiv_example/env.dart';
import 'package:instadiv_example/second_screen.dart';
import 'firebase_options.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> {
bool _initialized = false;
@override
void initState() {
super.initState();
initFirebase();
}
Future<void> initFirebase() async {
if (!mounted) return;
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
final instadivPlugin = Instadiv.getInstance();
instadivPlugin.setFirebase(Firebase.app());
instadivPlugin.setCred(apiKey, projectId);
setState(() {
_initialized = true;
});
}
@override
Widget build(BuildContext context) {
if (!_initialized) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
color: Colors.white,
child: const Center(
child: CircularProgressIndicator.adaptive(),
),
)));
}
return const InstaScreenWidget(child: HomePage());
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
final instadivPlugin = Instadiv.getInstance();
// Set onPress for 'OK' action of inapp dialog
// If not set it will open the link
instadivPlugin.setInAppCTA((url) {
print(url);
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const SecondScreen()));
});
// Set onPress for 'Story view CTA
// If not set it will open the link
instadivPlugin.setStoryViewCTA((url) {
print(url);
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const SecondScreen()));
});
return Scaffold(
appBar: AppBar(
title: const Text('InstaDiv Sample'),
),
body: getViewsFromClientFirebase(context),
);
}
Widget getViewsFromClientFirebase(BuildContext context){
return SingleChildScrollView(
child: Column(children: [
const SizedBox(height: 16),
InstaView(
viewId: 'fZ69czXvqNiZz4488gDI',
onPress: (uri) => Instadiv.getInstance()
.logEvent(context, 'screen_name', 'detail')),
const InstaView(
viewId: 'KMlgfgXisxDJGdJtcJKr'),
const SizedBox(height: 16),
Center(
child: ElevatedButton(
onPressed: () {
Instadiv.getInstance()
.logEvent(context, 'event_name', 'logged_in');
},
child: const Text(
'Press',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
)),
),
]),
);
}
}