diff --git a/lib/ui/home/tab_home.dart b/lib/ui/home/tab_home.dart index 9fc3903..a808e09 100644 --- a/lib/ui/home/tab_home.dart +++ b/lib/ui/home/tab_home.dart @@ -480,19 +480,13 @@ class _TabHomePageState extends State if (data.photoCount != 0) Positioned( bottom: 0, - left: 2, // alignement à gauche + left: 5, // alignement à gauche child: Container( margin: EdgeInsets.symmetric(vertical: 2), - child: badges.Badge( - badgeStyle: badges.BadgeStyle( - badgeColor: Colors.blue, - padding: EdgeInsets.all(data.photoCount >= 10 ? 2 : 6), - ), - badgeContent: Text(data.photoCount.toString(), - style: TextStyle(color: Colors.white)), - child: Icon( - Icons.camera_alt_sharp, - color: Colors.grey, + child: Container( + child: _reusableWidget.customPhotoCountIcon( + count: data.photoCount, + notifColor: BLACK_GREY, ), ), ), diff --git a/lib/ui/reusable/reusable_widget.dart b/lib/ui/reusable/reusable_widget.dart index f450acb..59c48b1 100644 --- a/lib/ui/reusable/reusable_widget.dart +++ b/lib/ui/reusable/reusable_widget.dart @@ -109,6 +109,54 @@ class ReusableWidget { ); } + Widget customPhotoCountIcon({ + int count = 0, + Color notifColor = Colors.grey, + Color labelColor = Colors.pinkAccent, + double notifSize = 24, + double labelSize = 14, + String position = 'right', + }) { + double? posLeft; + double? posRight = 0; + if (position == 'left') { + posLeft = 0; + posRight = null; + } + return Stack( + children: [ + Icon(Icons.camera_alt_sharp, color: notifColor, size: notifSize), + if (count > + 0) // Condition pour afficher le badge uniquement si count > 0 + Positioned( + left: posLeft, + right: posRight, + child: Container( + padding: EdgeInsets.all(1), + decoration: BoxDecoration( + color: labelColor, + borderRadius: BorderRadius.circular(labelSize), + ), + constraints: BoxConstraints( + minWidth: labelSize, + minHeight: labelSize, + ), + child: Center( + child: Text( + count.toString(), + style: TextStyle( + color: Colors.white, + fontSize: 8, + ), + textAlign: TextAlign.center, + ), + ), + ), + ), + ], + ); + } + Widget divider1() { return Divider(height: 0, color: Colors.grey[400]); } diff --git a/lib/ui/visit/visit_photo_typology.dart b/lib/ui/visit/visit_photo_typology.dart index c872124..57a29e3 100644 --- a/lib/ui/visit/visit_photo_typology.dart +++ b/lib/ui/visit/visit_photo_typology.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:badges/badges.dart' as badges; import 'package:mobdr/main.dart'; import 'package:mobdr/config/global_style.dart'; @@ -8,6 +7,7 @@ import 'package:mobdr/config/constant.dart'; import 'package:mobdr/db/box_photo_typology.dart'; import 'package:mobdr/model/visit_model.dart'; import 'package:mobdr/ui/visit/visit_photo_typology_list.dart'; +import 'package:mobdr/ui/reusable/reusable_widget.dart'; class VisitPhotoTypologyPage extends StatefulWidget { final VisitModel pp_visitModel; @@ -21,6 +21,9 @@ class VisitPhotoTypologyPage extends StatefulWidget { } class _VisitPhotoTypologyPageState extends State { + // initialize global function and reusable widget + final _reusableWidget = ReusableWidget(); + GestureDetector Function(BuildContext, int) _itemBuilder( List PhotoTypology) => (BuildContext context, int index) => GestureDetector( @@ -77,17 +80,14 @@ class _VisitPhotoTypologyPageState extends State { ), ), Container( - margin: EdgeInsets.symmetric(vertical: 0, horizontal: 10), - child: badges.Badge( - badgeStyle: badges.BadgeStyle( - badgeColor: Colors.blue, - padding: EdgeInsets.all(photoCount >= 10 ? 2 : 6), + margin: EdgeInsets.symmetric(vertical: 0), + child: Container( + child: _reusableWidget.customPhotoCountIcon( + count: photoCount, + notifColor: BLACK_GREY, ), - badgeContent: Text(photoCount.toString(), - style: TextStyle(color: Colors.white)), - child: Icon(Icons.camera_alt_sharp), ), - ), + ) ], ), );