refactor: Badge photo count
parent
9cb7907ab7
commit
1ddc35136a
|
|
@ -480,19 +480,13 @@ class _TabHomePageState extends State<TabHomePage>
|
||||||
if (data.photoCount != 0)
|
if (data.photoCount != 0)
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 2, // alignement à gauche
|
left: 5, // alignement à gauche
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: EdgeInsets.symmetric(vertical: 2),
|
margin: EdgeInsets.symmetric(vertical: 2),
|
||||||
child: badges.Badge(
|
child: Container(
|
||||||
badgeStyle: badges.BadgeStyle(
|
child: _reusableWidget.customPhotoCountIcon(
|
||||||
badgeColor: Colors.blue,
|
count: data.photoCount,
|
||||||
padding: EdgeInsets.all(data.photoCount >= 10 ? 2 : 6),
|
notifColor: BLACK_GREY,
|
||||||
),
|
|
||||||
badgeContent: Text(data.photoCount.toString(),
|
|
||||||
style: TextStyle(color: Colors.white)),
|
|
||||||
child: Icon(
|
|
||||||
Icons.camera_alt_sharp,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
Widget divider1() {
|
||||||
return Divider(height: 0, color: Colors.grey[400]);
|
return Divider(height: 0, color: Colors.grey[400]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:badges/badges.dart' as badges;
|
|
||||||
|
|
||||||
import 'package:mobdr/main.dart';
|
import 'package:mobdr/main.dart';
|
||||||
import 'package:mobdr/config/global_style.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/db/box_photo_typology.dart';
|
||||||
import 'package:mobdr/model/visit_model.dart';
|
import 'package:mobdr/model/visit_model.dart';
|
||||||
import 'package:mobdr/ui/visit/visit_photo_typology_list.dart';
|
import 'package:mobdr/ui/visit/visit_photo_typology_list.dart';
|
||||||
|
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
||||||
|
|
||||||
class VisitPhotoTypologyPage extends StatefulWidget {
|
class VisitPhotoTypologyPage extends StatefulWidget {
|
||||||
final VisitModel pp_visitModel;
|
final VisitModel pp_visitModel;
|
||||||
|
|
@ -21,6 +21,9 @@ class VisitPhotoTypologyPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VisitPhotoTypologyPageState extends State<VisitPhotoTypologyPage> {
|
class _VisitPhotoTypologyPageState extends State<VisitPhotoTypologyPage> {
|
||||||
|
// initialize global function and reusable widget
|
||||||
|
final _reusableWidget = ReusableWidget();
|
||||||
|
|
||||||
GestureDetector Function(BuildContext, int) _itemBuilder(
|
GestureDetector Function(BuildContext, int) _itemBuilder(
|
||||||
List<PhotoTypology> PhotoTypology) =>
|
List<PhotoTypology> PhotoTypology) =>
|
||||||
(BuildContext context, int index) => GestureDetector(
|
(BuildContext context, int index) => GestureDetector(
|
||||||
|
|
@ -77,17 +80,14 @@ class _VisitPhotoTypologyPageState extends State<VisitPhotoTypologyPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
margin: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
|
margin: EdgeInsets.symmetric(vertical: 0),
|
||||||
child: badges.Badge(
|
child: Container(
|
||||||
badgeStyle: badges.BadgeStyle(
|
child: _reusableWidget.customPhotoCountIcon(
|
||||||
badgeColor: Colors.blue,
|
count: photoCount,
|
||||||
padding: EdgeInsets.all(photoCount >= 10 ? 2 : 6),
|
notifColor: BLACK_GREY,
|
||||||
),
|
),
|
||||||
badgeContent: Text(photoCount.toString(),
|
|
||||||
style: TextStyle(color: Colors.white)),
|
|
||||||
child: Icon(Icons.camera_alt_sharp),
|
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue