mobdr/lib/ui/home/visit_photo_typology.dart

167 lines
5.6 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mobdr/main.dart';
import 'package:mobdr/config/global_style.dart';
import 'package:mobdr/config/constant.dart';
import 'package:mobdr/db/box_photo_typology.dart';
import 'package:mobdr/ui/home/visit_photo_typology_list.dart';
class VisitPhotoTypologyPage extends StatefulWidget {
final int pp_id_distrib;
final String pp_langage;
final int pp_id_visite;
final String pp_name;
final Function(int) onRefreshVisit;
VisitPhotoTypologyPage(
{Key? key,
required this.pp_id_distrib,
required this.pp_langage,
required this.pp_id_visite,
required this.pp_name,
required this.onRefreshVisit})
: super(key: key);
@override
_VisitPhotoTypologyPageState createState() => _VisitPhotoTypologyPageState();
}
class _VisitPhotoTypologyPageState extends State<VisitPhotoTypologyPage> {
GestureDetector Function(BuildContext, int) _itemBuilder(
List<PhotoTypology> PhotoTypology) =>
(BuildContext context, int index) => GestureDetector(
onTap: () {
Route route = MaterialPageRoute(
builder: (context) => VisitPhotoTypologyListPage(
pp_id_distrib: widget.pp_id_distrib,
pp_langage: widget.pp_langage,
pp_id_visite: widget.pp_id_visite,
pp_id_typologie:
PhotoTypology[index].id_photo_typologie,
pp_libelle_typologie: PhotoTypology[index].libelle,
));
Navigator.push(context, route).then(onGoBack);
},
/// TODO objectbox.noteBox.remove(PhotoTypology[index].id),
child: Container(
decoration: const BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.black12)),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 15.0, horizontal: 10.0),
child: Row(
children: <Widget>[
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_buildBadge(
widget.pp_id_visite,
PhotoTypology[index].id_photo_typologie,
PhotoTypology[index].libelle),
Icon(Icons.chevron_right, size: 20, color: SOFT_GREY),
],
),
),
],
),
),
),
);
Widget _buildBadge(int visitId, int photoTypologyId, String libelle) {
int photoCount =
objectbox.getVisitTypologiePhotoCount(visitId, photoTypologyId);
if (photoCount > 0) {
return Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
libelle,
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 4),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue,
),
child: Text(
photoCount.toString(),
style: TextStyle(color: Colors.white),
),
),
],
),
);
} else {
return Text(
libelle,
style: const TextStyle(
fontSize: 15.0,
),
);
}
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
FutureOr onGoBack(dynamic value) {
setState(() {});
}
Future<bool> onBackPressed() async {
// Navigate back to the visits page and refresh the data
int newPhotoCount = objectbox.getVisitPhotoCount(widget.pp_id_visite);
widget.onRefreshVisit(newPhotoCount);
return true;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return onBackPressed();
},
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
iconTheme: IconThemeData(
color: GlobalStyle.appBarIconThemeColor,
),
elevation: GlobalStyle.appBarElevation,
title: Text(
widget.pp_name,
style: GlobalStyle.appBarTitle,
),
backgroundColor: GlobalStyle.appBarBackgroundColor,
systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle),
body: Column(children: <Widget>[
Expanded(
child: StreamBuilder<List<PhotoTypology>>(
stream: objectbox.getPhotoTypologies(),
builder: (context, snapshot) => ListView.builder(
shrinkWrap: true,
//padding: const EdgeInsets.symmetric(horizontal: 20.0),
itemCount:
snapshot.hasData ? snapshot.data!.length : 0,
itemBuilder: _itemBuilder(snapshot.data ?? []))))
])));
}
}