tracker_annotations

Creator: coderz1093

Last updated:

0 purchases

tracker_annotations Image
tracker_annotations Images
Add to Cart

Description:

tracker annotations

Copywriter by Pong Pong (phonghoang2k) #
How to use #
Install #
To use tracker_generators, you will need your typical build_runner/code-generator setup.
First, install build_runner and tracker_generators by adding them to your pubspec.yaml file:
For a Flutter project:
flutter pub add tracker_annotations
flutter pub add dev:build_runner
flutter pub add dev:tracker_generators
copied to clipboard
This installs three packages:

build_runner, the tool to run code-generators
tracker_generators, the code generator
tracker_annotations, a package containing annotations for tracker_generators.

Run the generator #
To run the code generator, execute the following command:
dart run build_runner build
copied to clipboard
Note that like most code-generators, tracker_generators will need you to both import the annotation (tracker_annotations)
and use the part keyword on the top of your files.
As such, a file that wants to use tracker_generators will start with:
import 'package:tracker_annotations/tracker_annotations.dart';

part 'my_file.trackable.dart';

copied to clipboard
Creating a Trackable Page using Trackable #
An example is better than a long abstract explanation, so here's a typical Trackable class:

part 'sign_in_page.trackable.dart';

@trackable
class SignInPage extends StatefulWidget {
const SignInPage({Key? key}) : super(key: key);

@override
State<SignInPage> createState() => _SignInPageState();
}

class _SignInPageState extends State<SignInPage> with _$SignInPageMixin {
}
copied to clipboard

Using @trackable annotation to generate part 'sign_in_page.trackable.dart'; file.
part 'sign_in_page.trackable.dart'; file is generated from tracker_flutter_generator.dart
file, you can use it to track the screen.

class Trackable {
final String? contentType;
final String? referrer;

const Trackable({this.contentType, this.referrer});
}

copied to clipboard

Using Trackable class to track the screen.
Trackable class has two properties: contentType and referrer.

void main() {
runApp(const MyApp());

Trackable.observer = const MyObserver();
}
copied to clipboard

Set Trackable.observer to MyObserver class.

class MyObserver extends TrackableObserver {
@override
void onEnter(TrackerEventData event) {
// Do something when enter the screen
}

@override
void onExit(TrackerEventData event) {
// Do something when exit the screen
}
}
copied to clipboard

Implement TrackableObserver class to observe the screen.
Implement onEnter method to do something when enter the screen.
Implement onExit method to do something when exit the screen.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.