mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 09:13:00 +00:00
* updates * Update Gradle wrapper script to fetch latest version online and allow --version override * chore(analytics_integration): migrate Gradle build scripts to Kotlin DSL Convert Groovy build files to Kotlin DSL and bump Gradle wrapper. * chore(animation_example): migrate Gradle build scripts to Kotlin DSL Convert Groovy build files to Kotlin DSL. * chore(biometrics): migrate Gradle build scripts to Kotlin DSL Convert Groovy build files to Kotlin DSL. * chore(bmi_calculator): test test body * chore(bottom_sheet): test test body * chore(custom_home_drawer): migrate Gradle build scripts to Kotlin DSL Convert Groovy build files to Kotlin DSL and bump Gradle wrapper. * chore(covid19_mobile_app): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(dropdown_button): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(enabling_splash_screen): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(expense_planner): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(firebase_crash_reporting): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(firebase_google_authentication): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(flutter_date_pickers-master): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(getx_counter_app): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(google_signin): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(grid_layout): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(handling_routes): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(image_editor): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(image_from_network): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(infinite_list): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(load_local_image): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(load_local_json): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(lunch_app): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(navigation_drawer): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(news_memes_app): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(persist_key_value): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(push_notifications): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(save_data_locally_with_sqlite): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(scan_qr_code): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(simple_material_app): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(sliver_app_bar_example): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(stateful_widget): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(stateless_widgets): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(statless_counter_app): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(tic_tac_toe): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(tip_calculator): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(todo_list_using_provider): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(unit_testing): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_alert_dialog): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_bottom_nav_bar): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_custom_fonts): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_edittext): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_expansionpanel): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_firebase_db): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_gradient): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_http_get): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_interactiveviewer): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_listview): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_listwheelscrollview): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_platform_adaptive): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore(using_snackbar): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_stepper): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_tabs): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(using_theme): remove legacy nested android project Delete the redundant nested android/ project directory from the old layout. Also update pubspec.yaml SDK constraints and dependencies. * chore(view_pdf_file): migrate Gradle build scripts to Kotlin DSL Convert Groovy build.gradle/settings.gradle to Kotlin DSL and bump Gradle wrapper. * chore: ignore .trash directory * chore: remove IDE configs and PR template * chore(infinite_list): remove legacy nested android project * refactor(infinite_list): migrate theme to ColorScheme API * refactor(using_theme): migrate to ColorScheme API * refactor(analytics_integration): migrate Firebase Analytics API * refactor(firebase_google_authentication): migrate Google Sign-In API * refactor(covid19_mobile_app): migrate theme and buttons to current API * refactor(covid19_mobile_app): replace bezier_chart with fl_chart * refactor(image_editor): migrate image plugins and button styles * refactor(scan_qr_code): migrate mobile_scanner API * refactor(lunch_app): migrate to null safety * refactor(todo_list_using_provider): migrate to null safety * refactor(unit_testing): migrate to null safety * refactor(using_firebase_db): migrate Firebase Database API * fix(update_gradle_wrapper): edit gradle-wrapper.properties directly * refactor(push_notifications): migrate Firebase Messaging API * refactor(using_http_get): migrate to null safety * refactor(using_listview): migrate to null safety * refactor(using_listwheelscrollview): migrate to null safety * refactor(view_pdf_file): migrate to null safety * refactor(bottom_sheet): migrate to null safety * refactor(stateless_widgets): migrate to null safety * chore: regenerate Gradle wrapper * refactor: move maintenance scripts to Makefile * chore: remove generated and IDE files * fix: migrate image_editor to current plugins * fix: migrate news_memes_app share to share_plus * fix: migrate view_pdf_file to syncfusion pdf viewer * fix: update deprecated APIs * style: remove commented-out code
147 lines
4.0 KiB
Dart
147 lines
4.0 KiB
Dart
import 'package:analytics_integration/single_item_tile.dart';
|
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
/// initialize your firebase project
|
|
await Firebase.initializeApp();
|
|
runApp(FlutterAnalyticsApp());
|
|
}
|
|
|
|
class FlutterAnalyticsApp extends StatelessWidget {
|
|
/// create instance of FirebaseAnalytics as [analytics]
|
|
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
|
|
|
|
/// create observer for FirebaseAnalytics as [observer]
|
|
/// this observer sends events to Firebase Analytics when the
|
|
/// currently active route changes.
|
|
static FirebaseAnalyticsObserver observer =
|
|
FirebaseAnalyticsObserver(analytics: analytics);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Analytics',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
),
|
|
|
|
/// this is used to observe navigation changes in the app
|
|
/// and sending data back to Firebase Analytics
|
|
navigatorObservers: <NavigatorObserver>[observer],
|
|
home: FlutterAnalyticsHome(
|
|
title: 'Flutter Analytics',
|
|
analytics: analytics,
|
|
observer: observer,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class FlutterAnalyticsHome extends StatefulWidget {
|
|
final String title;
|
|
final FirebaseAnalytics analytics;
|
|
final FirebaseAnalyticsObserver observer;
|
|
|
|
FlutterAnalyticsHome({
|
|
super.key,
|
|
required this.title,
|
|
required this.analytics,
|
|
required this.observer,
|
|
});
|
|
|
|
@override
|
|
_FlutterAnalyticsHomeState createState() => _FlutterAnalyticsHomeState();
|
|
}
|
|
|
|
class _FlutterAnalyticsHomeState extends State<FlutterAnalyticsHome> {
|
|
late FirebaseAnalytics _analytics;
|
|
|
|
@override
|
|
void initState() {
|
|
/// initializing data to local variable [_analytics] for Firebase Analytics
|
|
/// that we made before for local use
|
|
_analytics = widget.analytics;
|
|
//// below three events are related to user which we are
|
|
//// sending to Firebase Analytics
|
|
_setUserIdInAnalytics();
|
|
_setUserPropertyInAnalytics();
|
|
_currentScreen();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBar(
|
|
title: Center(
|
|
child: Text(widget.title),
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 16,
|
|
),
|
|
SingleItemTile(
|
|
itemName: 'Carrot',
|
|
analytics: _analytics,
|
|
quantity: 1,
|
|
price: '100Rs',
|
|
),
|
|
SizedBox(
|
|
height: 16,
|
|
),
|
|
SingleItemTile(
|
|
itemName: 'Baby Carrot',
|
|
analytics: _analytics,
|
|
quantity: .5,
|
|
price: '50Rs',
|
|
),
|
|
SizedBox(
|
|
height: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
//// to create a unique user identifier for Analytics
|
|
//// send user id(if you app has)
|
|
Future<void> _setUserIdInAnalytics() async {
|
|
await _analytics.setUserId(id: 'alksj39hnfn49skvnghqwp40sm');
|
|
}
|
|
|
|
//// sending user related field to Analytics
|
|
/// below [name] is the name of the user property to set
|
|
/// [value] is the values of that property
|
|
Future<void> _setUserPropertyInAnalytics() async {
|
|
await _analytics.setUserProperty(
|
|
name: 'email',
|
|
value: 'johndoe@gmail.com',
|
|
);
|
|
}
|
|
|
|
/// Setting the current Screen of the app in [screenName]
|
|
/// and sending back to Analytics
|
|
Future<void> _currentScreen() async {
|
|
await _analytics.logEvent(
|
|
name: 'screen_view',
|
|
parameters: <String, Object>{
|
|
'screen_name': 'FlutterAnalyticsHome',
|
|
'screen_class': 'FlutterAnalyticsHome',
|
|
},
|
|
);
|
|
}
|
|
}
|