1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2026-08-25 01:05:36 +00:00
Files
flutter-examples/analytics_integration/lib/single_item_tile.dart
Nishant Srivastava 5c53498119 refactor: standardize Dart and Android config across all 54 apps
- Bump all apps to sdk >=3.0.0 <4.0.0 and add flutter_lints + a shared
  analysis_options.yaml to every app (flutter analyze is now green repo-wide)
- Fix real compile errors in firebase_google_authentication and image_editor,
  plus deprecated APIs (Matrix4, SvgPicture.color, textScaleFactor),
  missing async 'mounted' guards, and misc lints via dart fix + manual fixes
- Align pubspec 'name' with each folder and Android namespace/applicationId
  with the documented github.nisrulz.* convention
- Convert bmi_calculator from a legacy Flutter module to a standard app
  with a proper android/ scaffold; fix missing android:exported in launcher
  manifests across 22 apps so all Android builds pass
- Untrack generated build files (GeneratedPluginRegistrant,
  .flutter-plugins-dependencies) and ignore them
2026-08-17 17:26:39 +02:00

139 lines
4.1 KiB
Dart

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/material.dart';
class SingleItemTile extends StatefulWidget {
final String price;
final String itemName;
final double quantity;
final FirebaseAnalytics analytics;
const SingleItemTile({super.key,
required this.itemName,
required this.price,
required this.quantity,
required this.analytics,
});
@override
_SingleItemTileState createState() => _SingleItemTileState();
}
class _SingleItemTileState extends State<SingleItemTile> {
/// [addedToCart] this variable is used to to justify that product is added in
/// cart or not
late bool addedToCart;
@override
void initState() {
addedToCart = false;
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.green,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset(
'asset/carrot.jpg',
height: 200,
width: 400,
),
Container(
color: Colors.green,
height: .5,
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(16.0) + EdgeInsets.only(left: 8),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.price,
style: TextStyle(
color: Colors.red[600],
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Text(
widget.itemName,
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
Text(
'${widget.quantity} kg',
style: TextStyle(
color: Colors.grey,
fontSize: 12,
),
),
],
),
InkWell(
onTap: () {
setState(() {
addedToCart = !addedToCart;
});
_sendCartEvent(widget.price, widget.itemName,
widget.quantity, addedToCart);
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.green,
),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
addedToCart ? 'Remove from Cart' : 'Add to Cart +',
style: TextStyle(
color: Colors.red[600],
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
),
],
),
),
],
),
);
}
/// to make custom event in Analytics you can create your own Map
/// below in [name] field give your event name identifier
/// and in [parameters] filed create your map
Future<void> _sendCartEvent(
String price, String itemName, double quantity, bool addedToCart) async {
await widget.analytics.logEvent(
name: 'item',
parameters: <String, Object>{
'price': price,
'itemName': itemName,
'quantity': quantity,
'bool': addedToCart,
},
);
}
}