vwo_insights_flutter_sdk 0.0.7 vwo_insights_flutter_sdk: ^0.0.7 copied to clipboard
VWO Insights helps you analyze user behavior in your application based on interactions such as application launch, taps, scrolls, and flings.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:vwo_insights_flutter_sdk/vwo_insights_flutter_sdk.dart';
import 'package:vwo_insights_flutter_sdk_example/Screen3.dart';
import 'package:vwo_insights_flutter_sdk_example/utils/my_navigator_observer.dart';
import './providers/common_provider.dart';
import './screens/profile/profile.dart';
import 'package:provider/provider.dart';
import './Screen1.dart';
import './screens/sorting/sorting_campaign.dart';
import 'demo_screen.dart';
import 'screens/variable/variable_campaign.dart';
const bool useRoutes = true;
void main() {
if (useRoutes) {
runApp(const MyApp());
} else {
runApp(const MyAppNoRoute());
}
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late StreamSubscription<int> _streamSubscription;
@override
void dispose() {
_streamSubscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
var app = MaterialApp(
title: 'Flutter Demo',
routes: {
"/": (context) => const Screen1(),
'/third': (context) => const Screen3(),
'/demo': (context) => const DemoScreen(),
'/housing': (context) => const VariableCampaign(),
'/phone': (context) => const SortingCampaign(),
'/profile': (context) => const Profile(),
},
navigatorObservers: [
VwoNavigatorObserver(),
MyNavigatorObserver(),
],
);
return MultiProvider(
providers: [ChangeNotifierProvider(create: (_) => CommonProvider())],
child: app,
);
}
}
class MyAppNoRoute extends StatefulWidget {
const MyAppNoRoute({super.key});
@override
State<MyAppNoRoute> createState() => _MyAppNoRoute();
}
class _MyAppNoRoute extends State<MyAppNoRoute> {
late StreamSubscription<int> _streamSubscription;
@override
void dispose() {
_streamSubscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
var app = const MaterialApp(
title: 'Flutter Demo No routes',
home: Screen1(),
);
VwoFlutter().screenChanged("/");
return MultiProvider(
providers: [ChangeNotifierProvider(create: (_) => CommonProvider())],
child: app,
);
}
}
void showScreen(BuildContext context, String route) {
if (useRoutes) {
Navigator.of(context).pushNamed(route);
} else {
Widget screen;
if (route == '/third') {
screen = const Screen3();
} else if (route == '/') {
screen = const Screen1();
} else if (route == '/demo') {
screen = const DemoScreen();
} else if (route == '/housing') {
screen = const VariableCampaign();
} else if (route == '/phone') {
screen = const SortingCampaign();
} else if (route == '/profile') {
screen = const Profile();
} else {
screen = const Screen1();
}
VwoFlutter().screenChanged(route);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => screen
), // Direct navigation without named routes
);
}
}