1+
2+ import 'package:flutter/material.dart' ;
3+
4+ import '../funnels_manager/analytix_funnel.dart' ;
5+ import '../funnels_manager/funnels.dart' ;
6+ import '../funnels_manager/funnels_manager.dart' ;
7+
8+ class SimpleFunnelExampleScreen extends StatefulWidget {
9+ const SimpleFunnelExampleScreen ({super .key});
10+
11+ @override
12+ State <SimpleFunnelExampleScreen > createState () => _SimpleFunnelExampleScreenState ();
13+ }
14+
15+ class _SimpleFunnelExampleScreenState extends State <SimpleFunnelExampleScreen > {
16+
17+ final PageController _pageController = PageController ();
18+
19+ @override
20+ void initState () {
21+ // Start tracking Funnel 2
22+ FunnelsManager ().start (AnalytixFunnel (Funnels .funnel_2, shouldCountTime: true ));
23+
24+ // Start track Funnel 3
25+ FunnelsManager ().start (AnalytixFunnel (Funnels .funnel_3, shouldCountTime: true ));
26+ FunnelsManager ().track (Funnels .funnel_3, "start" );
27+ super .initState ();
28+ }
29+
30+ @override
31+ void dispose () {
32+ // finish the funnel if a user decides to leave the screen
33+ // before finishing the whole steps. This won't affect if the user finishes all steps
34+ FunnelsManager ().finish (Funnels .funnel_2, "finish" );
35+ FunnelsManager ().finish (Funnels .funnel_3, "finish" );
36+
37+ super .dispose ();
38+ }
39+
40+ @override
41+ Widget build (BuildContext context) {
42+ return Scaffold (
43+ appBar: AppBar (
44+ title: const Text ('Simple Funnel Example' ),
45+ ),
46+ body: Center (
47+ child: PageView .builder (
48+ itemCount: 4 ,
49+ controller: _pageController,
50+ physics: const NeverScrollableScrollPhysics (),
51+ itemBuilder: (context, index) {
52+ var indexUserFriendly = index+ 1 ;
53+ return Column (
54+ children: [
55+ Center (
56+ child: ListTile (
57+ title: Text ('Page #$indexUserFriendly ' ),
58+ onTap: () {
59+ // start a new funnel if possible - to track how much time we stay at each screen
60+ FunnelsManager ().start (AnalytixFunnel (Funnels .funnel_3, shouldCountTime: true ));
61+ // Track the event
62+ FunnelsManager ().track (Funnels .funnel_3, "step_$indexUserFriendly " );
63+ FunnelsManager ().finish (Funnels .funnel_3, "finish" );
64+
65+
66+ if (indexUserFriendly < 4 ) {
67+ // start a new funnel for the next screen
68+ FunnelsManager ().start (AnalytixFunnel (Funnels .funnel_3, shouldCountTime: true ));
69+ _pageController.animateToPage (indexUserFriendly, duration: const Duration (milliseconds: 500 ), curve: Curves .easeInOut);
70+ } else {
71+ Navigator .pop (context);
72+ }
73+ },
74+ ),
75+ ),
76+ ],
77+ );
78+ },
79+ )
80+ ),
81+ );
82+ }
83+ }
0 commit comments