refactor: Badge photo count

release/mobdr-v0.0.1
Frédérik Benoist 2023-06-03 21:44:36 +02:00
parent 9cb7907ab7
commit 1ddc35136a
3 changed files with 63 additions and 21 deletions

View File

@ -480,19 +480,13 @@ class _TabHomePageState extends State<TabHomePage>
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,
),
),
),

View File

@ -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: <Widget>[
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]);
}

View File

@ -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<VisitPhotoTypologyPage> {
// initialize global function and reusable widget
final _reusableWidget = ReusableWidget();
GestureDetector Function(BuildContext, int) _itemBuilder(
List<PhotoTypology> PhotoTypology) =>
(BuildContext context, int index) => GestureDetector(
@ -77,17 +80,14 @@ class _VisitPhotoTypologyPageState extends State<VisitPhotoTypologyPage> {
),
),
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),
),
),
)
],
),
);