wip map update (filter + icons (tbt)) + added section_page_detail

This commit is contained in:
Thomas Fransolet 2024-04-17 23:34:53 +02:00
parent d9efad47f8
commit cba728884f
9 changed files with 613 additions and 146 deletions

View File

@ -89,8 +89,6 @@ class _EventPopupState extends State<EventPopup> {
return options;
}
@override
Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);

View File

@ -23,6 +23,7 @@ import 'package:tablet_app/Models/WeatherData.dart';
import 'package:tablet_app/Screens/Agenda/agenda_view.dart';
import 'package:tablet_app/Screens/Article/article_view.dart';
import 'package:tablet_app/Screens/Configuration/config_view.dart';
import 'package:tablet_app/Screens/MainView/section_page_detail.dart';
import 'package:tablet_app/Screens/Weather/weather_view.dart';
import 'package:tablet_app/Screens/Map/map_context.dart';
import 'package:tablet_app/Screens/Map/map_view.dart';
@ -38,6 +39,9 @@ import 'package:tablet_app/Services/downloadService.dart';
import 'package:tablet_app/app_context.dart';
import 'package:tablet_app/constants.dart';
import 'package:intl/intl.dart';
import 'package:http/http.dart' as http;
import 'package:image/image.dart' as IMG;
import 'dart:ui' as ui;
import '../Quizz/quizz_view.dart';
import 'language_selection.dart';
@ -100,7 +104,7 @@ class _MainViewWidget extends State<MainViewWidget> {
/*if (!MQTTHelper.instance.isInstantiated)
MQTTHelper.instance.connect(appContext);*/
if(sectionSelected != null) {
/*if(sectionSelected != null) {
var elementToShow;
print(sectionSelected!.type);
switch (sectionSelected!.type) {
@ -112,7 +116,22 @@ class _MainViewWidget extends State<MainViewWidget> {
longitude: null,
title: '',
description: '')),
child: MapViewWidget(section: sectionSelected!) /*FutureBuilder(
child: FutureBuilder(
future: getByteIcon(sectionSelected!),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MapViewWidget(section: sectionSelected!, markerIcon: snapshot.data);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
) /*FutureBuilder(
future: _url,
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
? WebViewWidget(url: snapshot.data,)
@ -195,8 +214,49 @@ class _MainViewWidget extends State<MainViewWidget> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
//color: Colors.grey,
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Scaffold(
body: ChangeNotifierProvider<MapContext>(
create: (_) =>
MapContext(new MapMarker(
latitude: null,
longitude: null,
title: '',
description: '')),
child: FutureBuilder(
future: getByteIcon(sectionSelected!),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MapViewWidget(section: sectionSelected!, markerIcon: snapshot.data);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
) /*FutureBuilder(
future: _url,
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
? WebViewWidget(url: snapshot.data,)
: CircularProgressIndicator()),*/
)
);
},
),// For pushAndRemoveUntil
);
},
child: Container(
color: Colors.grey,
//width: size.width * 0.8,
child: Padding(
padding: const EdgeInsets.only(left: 15.0, top: 10.0, bottom: 10.0),
@ -222,6 +282,7 @@ class _MainViewWidget extends State<MainViewWidget> {
),
),
),
),
Container(
//width: size.width,
//color: Colors.green,
@ -327,7 +388,7 @@ class _MainViewWidget extends State<MainViewWidget> {
),
),*/
);
} else {
} else {*/
return Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
@ -384,7 +445,7 @@ class _MainViewWidget extends State<MainViewWidget> {
return Text("");
}
else {
return getGridSections(appContext);
return getGridSections(appContext, textColor);
}
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
@ -396,7 +457,7 @@ class _MainViewWidget extends State<MainViewWidget> {
);
}
}
) : getGridSections(appContext),
) : getGridSections(appContext, textColor),
),
),
/*if(configurationDTO.weatherCity != null && configurationDTO.weatherCity!.length > 2 && configurationDTO.weatherResult != null)
@ -417,7 +478,7 @@ class _MainViewWidget extends State<MainViewWidget> {
]),
),
);
}
//}
}
Future<ConfigurationDTO?> getCurrentConfiguration(dynamic appContext) async {
@ -509,7 +570,7 @@ class _MainViewWidget extends State<MainViewWidget> {
return sectionsLocal;
}
getGridSections(AppContext appContext) {
getGridSections(AppContext appContext, Color textColor) {
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
if(sectionsLocal != null) {
@ -526,7 +587,16 @@ class _MainViewWidget extends State<MainViewWidget> {
return InkWell(
onTap: () {
setState(() {
sectionSelected = sectionsLocal![index];
//sectionSelected = sectionsLocal![index];
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SectionPageDetail(configurationDTO: configurationDTO, sectionDTO: sectionsLocal![index], textColor: textColor, isImageBackground: isImageBackground, elementToShow: getContent(sectionsLocal![index], isImageBackground));
},
),// For pushAndRemoveUntil
);
});
},
child: Container(
@ -599,21 +669,6 @@ class _MainViewWidget extends State<MainViewWidget> {
}
}
double calculateFontSize(double parentWidth, double parentHeight, double baseSize) {
// La taille de base est basée sur la taille définie dans vos constantes (kWebMenuTitleDetailSize ou kMenuTitleDetailSize).
// Vous pouvez ajuster ce facteur en fonction de vos besoins.
double scaleFactor = 0.8;
// Calculez la taille de la police en fonction de la largeur et de la hauteur maximales disponibles
//double calculatedFontSize = parentWidth * scaleFactor;
// Vous pouvez également prendre en compte la hauteur ici si nécessaire
double calculatedFontSize = min(parentWidth, parentHeight) * scaleFactor;
// Utilisez la plus petite valeur entre la taille de base et la taille calculée
return calculatedFontSize < baseSize ? calculatedFontSize : baseSize;
}
boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) {
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
return BoxDecoration(
@ -635,3 +690,118 @@ boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) {
],
);
}
Future<List<Map<String, dynamic>>> getByteIcons(SectionDTO section) async {
var mapDTO = MapDTO.fromJson(jsonDecode(section.data!));
var selectedMarkerIcon;
if (mapDTO != null && mapDTO.iconSource != null) {
if (kIsWeb) {
Uint8List fileData = await http.readBytes(Uri.parse(mapDTO.iconSource!));
selectedMarkerIcon = resizeImage(fileData, 40);
} else {
final ByteData imageData = await NetworkAssetBundle(Uri.parse(mapDTO.iconSource!)).load("");
selectedMarkerIcon = await getBytesFromAsset(imageData, 50);
}
} else {
// Icône par défaut
final ByteData bytes = await rootBundle.load('assets/icons/marker.png');
selectedMarkerIcon = await getBytesFromAsset(bytes, 25);
}
List<Map<String, dynamic>> icons = [];
icons.add({'id': null, 'icon': selectedMarkerIcon});
mapDTO!.categories!.forEach((cat) async {
if (cat.iconUrl != null) {
Uint8List categoryIcon;
if (kIsWeb) {
categoryIcon = await http.readBytes(Uri.parse(cat.iconUrl!));
} else {
final ByteData imageData = await NetworkAssetBundle(Uri.parse(cat.iconUrl!)).load("");
categoryIcon = await getBytesFromAsset(imageData, 50);
}
icons.add({'id': cat.id, 'icon': categoryIcon});
}
});
return icons;
}
Future<Uint8List> getBytesFromAsset(ByteData data, int width) async {
//ByteData data = await rootBundle.load(path);
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(),
targetWidth: width);
ui.FrameInfo fi = await codec.getNextFrame();
return (await fi.image.toByteData(format: ui.ImageByteFormat.png))
!.buffer
.asUint8List();
}
Uint8List resizeImage(Uint8List data, int width) {
Uint8List resizedData = data;
IMG.Image img = IMG.decodeImage(data)!;
IMG.Image resized = IMG.copyResize(img, width: width);
resizedData = Uint8List.fromList(IMG.encodeJpg(resized));
return resizedData;
}
Widget getContent(SectionDTO sectionSelected, bool isImageBackground) {
switch (sectionSelected.type) {
case SectionType.Map : // MAP
return ChangeNotifierProvider<MapContext>(
create: (_) =>
MapContext(new MapMarker(
latitude: null,
longitude: null,
title: '',
description: '')),
child: FutureBuilder(
future: getByteIcons(sectionSelected),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MapViewWidget(section: sectionSelected, icons: snapshot.data);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
) /*FutureBuilder(
future: _url,
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
? WebViewWidget(url: snapshot.data,)
: CircularProgressIndicator()),*/
);
case SectionType.Web : // WEB
return WebView(section: sectionSelected);
case SectionType.Video : // Video
return VideoView(section: sectionSelected);
case SectionType.Slider :
return SliderView(section: sectionSelected);
case SectionType.Menu :
return MenuView(section: sectionSelected!, isImageBackground: isImageBackground);
case SectionType.Quizz :
return QuizzView(section: sectionSelected);
case SectionType.Pdf :
return PDFViewWidget(section: sectionSelected);
case SectionType.Puzzle :
return PuzzleView(section: sectionSelected);
case SectionType.Agenda :
return AgendaView(section: sectionSelected);
/*case SectionType.article : // TODO
elementToShow = ArticleView(section: sectionSelected);
break;*/
case SectionType.Weather :
return WeatherView(section: sectionSelected);
default:
return Text("Ce type n'est pas supporté");
};
}

View File

@ -0,0 +1,247 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:enum_to_string/enum_to_string.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:manager_api/api.dart';
import 'package:provider/provider.dart';
import 'package:tablet_app/Components/loading_common.dart';
import 'package:tablet_app/Components/multi_select_container.dart';
import 'package:tablet_app/Helpers/ImageCustomProvider.dart';
import 'package:tablet_app/Helpers/translationHelper.dart';
import 'package:tablet_app/Models/map-marker.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/Screens/Map/geo_point_filter.dart';
import 'package:tablet_app/Screens/Map/map_context.dart';
import 'package:html/parser.dart' show parse;
import 'package:tablet_app/app_context.dart';
import 'package:tablet_app/constants.dart';
class SectionPageDetail extends StatefulWidget {
final ConfigurationDTO configurationDTO;
final SectionDTO sectionDTO;
final Uint8List? selectedMarkerIcon;
final Color textColor;
final bool isImageBackground;
final Widget elementToShow;
const SectionPageDetail({
Key? key,
required this.configurationDTO,
required this.sectionDTO,
this.selectedMarkerIcon,
required this.textColor,
required this.isImageBackground,
required this.elementToShow,
}) : super(key: key);
@override
_SectionPageDetailState createState() => _SectionPageDetailState();
}
class _SectionPageDetailState extends State<SectionPageDetail> {
bool init = false;
@override
Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
Size size = MediaQuery.of(context).size;
return Scaffold(
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
child: Container(
height: size.height,
width: size.width,
color: widget.configurationDTO.imageId == null ? widget.configurationDTO.secondaryColor != null ? new Color(int.parse(widget.configurationDTO.secondaryColor!.split('(0x')[1].split(')')[0], radix: 16)): kBackgroundGrey : null,
decoration: widget.configurationDTO.imageId != null ? BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.white.withOpacity(0.8), BlendMode.lighten),
image: ImageCustomProvider.getImageProvider(appContext, widget.configurationDTO.imageId!, widget.configurationDTO.imageSource!),
),
) : null,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration : BoxDecoration(
color: kBackgroundLight,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(tabletAppContext.configuration!.roundedValue?.toDouble() ?? 30.0),
boxShadow: [
BoxShadow(
color: kBackgroundSecondGrey,
spreadRadius: 0.5,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
),
child: Column(
children: [
Expanded(
flex: 1,
//height: size.height * 0.1,
child: Container(
//color: Colors.greenAccent,
width: size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
//color: Colors.grey,
//width: size.width * 0.8,
child: Padding(
padding: const EdgeInsets.only(left: 15.0, top: 10.0, bottom: 10.0),
child: Container(
//color: Colors.grey,
child: AspectRatio(
aspectRatio: 4 / 4,
child: widget.isImageBackground ? Container(
/*width: 125,
height: 125,*/
decoration: boxDecoration(appContext, widget.sectionDTO, true),
) : Container(
decoration: BoxDecoration(
color: widget.sectionDTO.imageSource == null ? kBackgroundLight : null, // default color if no image
shape: BoxShape.rectangle,
image: widget.sectionDTO.imageSource != null ? new DecorationImage(
fit: BoxFit.cover,
image: ImageCustomProvider.getImageProvider(appContext, widget.sectionDTO.imageId!, widget.sectionDTO.imageSource!),
): null,
),
),
),
),
),
),
Container(
//width: size.width,
//color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Align(
alignment: Alignment.center,
child: HtmlWidget(
widget.sectionDTO.title!.firstWhere((translation) => translation.language == appContext.getContext().language).value!,
textStyle: new TextStyle(fontSize: kIsWeb ? kWebSectionTitleDetailSize : kSectionTitleDetailSize, color: widget.textColor, fontFamily: 'Roboto'),
)
),
if(widget.sectionDTO.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value != null && widget.sectionDTO.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value!.trim().isNotEmpty)
Align(
//alignment: Alignment.center,
child: HtmlWidget(
widget.sectionDTO.description!.firstWhere((translation) => translation.language == appContext.getContext().language).value!,
textStyle: new TextStyle(fontSize: kIsWeb? kWebSectionDescriptionDetailSize : kSectionDescriptionDetailSize, color: widget.textColor, fontFamily: 'Roboto'),
)
)
],
),
),
Padding(
padding: const EdgeInsets.only(right: 15.0),
child: Container(
height: size.height *0.08,
width: size.width *0.08,
child: FittedBox(
child: FloatingActionButton.extended(
backgroundColor: kBackgroundColor,
focusColor: kBackgroundColor,
splashColor: kBackgroundColor,
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.arrow_back, color: Colors.grey),
label: Text(TranslationHelper.getFromLocale("menu", appContext.getContext()), style: TextStyle(color: Colors.black))
),
),
),
)
],
),
),
),
Expanded(
flex: 9,
child: Padding(
padding: widget.sectionDTO.type != SectionType.Slider ? const EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0) : const EdgeInsets.only(top: 10.0),
child: Container(
width: size.width,
//height: size.height * 0.9,
/*decoration: sectionSelected!.type != SectionType.Video && sectionSelected!.type != SectionType.Web && sectionSelected!.type != SectionType.Slider && sectionSelected!.type != SectionType.Map ? BoxDecoration(
//color: kBackgroundLight,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(tabletAppContext.configuration!.roundedValue?.toDouble() ?? 30.0),
/*boxShadow: [
BoxShadow(
color: kBackgroundSecondGrey,
spreadRadius: 0.5,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],*/
) :null,*/
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: widget.elementToShow),
),
),
)
],
),
),
),
),
),
/*floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Container(
height: size.height *0.08,
width: size.width *0.08,
child: FittedBox(
child: FloatingActionButton.extended(
backgroundColor: kBackgroundColor,
focusColor: kBackgroundColor,
splashColor: kBackgroundColor,
onPressed: () {
setState(() {
sectionSelected = null;
});
},
icon: Icon(Icons.arrow_back, color: Colors.grey),
label: Text("Menu", style: TextStyle(color: Colors.black))
),
),
),
),*/
);
}
}
boxDecoration(AppContext appContext, SectionDTO section, bool isSelected) {
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
return BoxDecoration(
color: !isSelected ? kBackgroundLight : section.imageSource == null ? kBackgroundLight : null,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(tabletAppContext.configuration!.roundedValue?.toDouble() ?? 30.0),
image: section.imageSource != null ? new DecorationImage(
fit: BoxFit.cover,
colorFilter: !isSelected? new ColorFilter.mode(kBackgroundLight.withOpacity(0.2), BlendMode.dstATop) : null,
image: ImageCustomProvider.getImageProvider(appContext, section.imageId!, section.imageSource!),
): null,
boxShadow: [
BoxShadow(
color: kBackgroundSecondGrey,
spreadRadius: 0.5,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
);
}

View File

@ -19,8 +19,9 @@ class GeoPointFilter extends StatefulWidget {
final List<GeoPointDTO> geoPoints;
final List<CategorieDTO> categories;
final Function(List<GeoPointDTO>?) filteredPoints;
final MapProvider provider;
GeoPointFilter({required this.language, required this.geoPoints, required this.categories, required this.filteredPoints});
GeoPointFilter({required this.language, required this.geoPoints, required this.categories, required this.filteredPoints, required this.provider});
@override
_GeoPointFilterState createState() => _GeoPointFilterState();
@ -33,6 +34,7 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
late ValueNotifier<String> _searchTextNotifier;
final TextEditingController _searchController = TextEditingController();
FocusNode focusNode = new FocusNode();
bool _isExpanded = true;
@override
void initState() {
@ -51,6 +53,12 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
super.dispose();
}
void _toggleExpansion() {
setState(() {
_isExpanded = !_isExpanded;
});
}
void _onSearchTextChanged() {
//filterNodes(_searchTextNotifier.value);
}
@ -100,10 +108,10 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
: _filterNodesBySearchText(searchText);
// if unfocus, then
if(searchText.isEmpty && !focusNode.hasFocus) {
//if(searchText.isEmpty) {
// widget.filteredPoints = //todo
sendFilteredGeoPoint();
}
//}
});
}
@ -157,7 +165,7 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
return Positioned(
left: 5,
top: 35,
top: widget.provider == MapProvider.Google ? 10 : 35,
child: Container(
width: size.width * 0.3,
decoration: BoxDecoration(
@ -168,8 +176,14 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8.0, top: 4.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 60,
width: (size.width * 0.20),
child: Padding(
padding: const EdgeInsets.only(left: 10.0, bottom: 8.0, top: 4.0),
child: TextField(
focusNode: focusNode,
controller: _searchController,
@ -203,12 +217,29 @@ class _GeoPointFilterState extends State<GeoPointFilter> {
),
),
),
),
SizedBox(
width: 50,
height: 60,
child: Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: _toggleExpansion,
child: Padding(
padding: const EdgeInsets.only(top: 4.0, right: 3.0),
child: Icon(_isExpanded ? Icons.expand_more : Icons.chevron_right, color: primaryColor),
),
),
),
),
],
),
ValueListenableBuilder<String>(
valueListenable: _searchTextNotifier,
builder: (context, value, _) {
return Container(
//color: Colors.greenAccent,
height: size.height * 0.65,
height: _isExpanded ? widget.provider == MapProvider.Google ? size.height * 0.68 : size.height * 0.65 : 0,
width: size.width * 0.3,
child: GenerateTree(
data: _filteredNodes,

View File

@ -16,13 +16,13 @@ import 'package:tablet_app/app_context.dart';
import 'package:tablet_app/constants.dart';
class GoogleMapView extends StatefulWidget {
final MapDTO? mapDTO;
final Uint8List? selectedMarkerIcon;
final MapDTO mapDTO;
final List<Map<String, dynamic>> icons;
final String? language;
const GoogleMapView({
Key? key,
this.mapDTO,
this.selectedMarkerIcon,
required this.mapDTO,
required this.icons,
this.language,
}) : super(key: key);
@ -59,7 +59,8 @@ class _GoogleMapViewState extends State<GoogleMapView> {
double.tryParse(mapMarker.latitude!)!,
double.tryParse(mapMarker.longitude!)!,
),
icon: widget.selectedMarkerIcon != null ? BitmapDescriptor.fromBytes(widget.selectedMarkerIcon!) : BitmapDescriptor.defaultMarker,
icon: point.categorie == null ? BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == null).first['icon']) : widget.icons.any((i) => i['id'] == point.categorieId) ? BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == point.categorieId).first['icon']) : BitmapDescriptor.fromBytes(widget.icons.where((i) => i['id'] == null).first['icon']), //widget.selectedMarkerIcon,
//widget.selectedMarkerIcon != null ? BitmapDescriptor.fromBytes(widget.selectedMarkerIcon!) : BitmapDescriptor.defaultMarker,
/*icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueYellow,
),*/
@ -173,7 +174,7 @@ class _GoogleMapViewState extends State<GoogleMapView> {
},
),
),
Positioned(
/*Positioned(
left: 5,
top: 35,
child: SizedBox(
@ -214,7 +215,7 @@ class _GoogleMapViewState extends State<GoogleMapView> {
},
),
),
),
),*/
],
);
}

View File

@ -20,13 +20,13 @@ import 'package:tablet_app/constants.dart';
class MapBoxView extends StatefulWidget {
final MapDTO? mapDTO;
final List<GeoPointDTO> geoPoints;
final Uint8List? selectedMarkerIcon;
final List<Map<String, dynamic>> icons;
final String? language;
const MapBoxView({
Key? key,
this.mapDTO,
required this.geoPoints,
this.selectedMarkerIcon,
required this.icons,
this.language,
}) : super(key: key);
@ -87,7 +87,7 @@ class _MapBoxViewState extends State<MapBoxView> {
symbolSortKey: 10,
iconColor: 0,
iconImage: null,
image: widget.selectedMarkerIcon, //widget.selectedMarkerIcon,
image: point.categorie == null ? widget.icons.where((i) => i['id'] == null).first['icon'] : widget.icons.any((i) => i['id'] == point.categorieId) ? widget.icons.where((i) => i['id'] == point.categorieId).first['icon'] : widget.icons.where((i) => i['id'] == null).first['icon'], //widget.selectedMarkerIcon,
)); // ,
i++;

View File

@ -1,33 +1,34 @@
import 'dart:async';
//import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
// 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
// 'package:flutter/services.dart';
//import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:manager_api/api.dart';
import 'package:provider/provider.dart';
import 'package:tablet_app/Components/loading.dart';
import 'package:tablet_app/Components/loading_common.dart';
/*import 'package:tablet_app/Components/loading.dart';
import 'package:tablet_app/Components/loading_common.dart';*/
import 'package:tablet_app/Models/map-marker.dart';
import 'dart:ui' as ui;
//import 'dart:ui' as ui;
import 'package:flutter/widgets.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/Screens/Map/geo_point_filter.dart';
import 'package:tablet_app/Screens/Map/map_box_view.dart';
import 'package:tablet_app/Screens/Map/marker_view.dart';
import 'package:http/http.dart' as http;
//import 'package:http/http.dart' as http;
import '../../app_context.dart';
import 'google_map_view.dart';
import 'package:image/image.dart' as IMG;
//import 'package:image/image.dart' as IMG;
//Set<Marker> markers = {};
List<MapMarker> markersList = [];
class MapViewWidget extends StatefulWidget {
final SectionDTO? section;
MapViewWidget({Key? key, this.section}) : super(key: key);
final SectionDTO section;
final List<Map<String, dynamic>> icons;
MapViewWidget({Key? key, required this.section, required this.icons}) : super(key: key);
@override
_MapViewWidget createState() => _MapViewWidget();
@ -36,10 +37,10 @@ class MapViewWidget extends StatefulWidget {
class _MapViewWidget extends State<MapViewWidget> {
MapDTO? mapDTO;
//Completer<GoogleMapController> _controller = Completer();
Uint8List? selectedMarkerIcon;
//Uint8List? selectedMarkerIcon;
late ValueNotifier<List<GeoPointDTO>> _geoPoints = ValueNotifier<List<GeoPointDTO>>([]);
Future<Uint8List> getBytesFromAsset(ByteData data, int width) async {
/*Future<Uint8List> getBytesFromAsset(ByteData data, int width) async {
//ByteData data = await rootBundle.load(path);
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(),
targetWidth: width);
@ -47,11 +48,11 @@ class _MapViewWidget extends State<MapViewWidget> {
return (await fi.image.toByteData(format: ui.ImageByteFormat.png))
!.buffer
.asUint8List();
}
}*/
@override
void initState() {
mapDTO = MapDTO.fromJson(jsonDecode(widget.section!.data!));
mapDTO = MapDTO.fromJson(jsonDecode(widget.section.data!));
_geoPoints.value = mapDTO!.points!;
super.initState();
}
@ -73,10 +74,21 @@ class _MapViewWidget extends State<MapViewWidget> {
//final mapContext = Provider.of<MapContext>(context);
final appContext = Provider.of<AppContext>(context);
TabletAppContext tabletAppContext = appContext.getContext() as TabletAppContext;
return FutureBuilder(
/*return FutureBuilder(
future: getByteIcon(mapDTO!.iconSource),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
);*/
return Stack(
children: <Widget>[
ValueListenableBuilder<List<GeoPointDTO>>(
@ -84,12 +96,12 @@ class _MapViewWidget extends State<MapViewWidget> {
builder: (context, value, _) {
switch(mapDTO!.mapProvider) {
case MapProvider.Google:
return GoogleMapView(language: appContext.getContext().language, mapDTO: mapDTO, selectedMarkerIcon: selectedMarkerIcon);
return GoogleMapView(language: appContext.getContext().language, mapDTO: mapDTO!, icons: widget.icons);
case MapProvider.MapBox:
return MapBoxView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO, selectedMarkerIcon: selectedMarkerIcon);
return MapBoxView(language: appContext.getContext().language, geoPoints: value, mapDTO: mapDTO, icons: widget.icons);
default:
// By default google
return GoogleMapView(language: appContext.getContext().language, mapDTO: mapDTO, selectedMarkerIcon: selectedMarkerIcon);
return GoogleMapView(language: appContext.getContext().language, mapDTO: mapDTO!, icons: widget.icons);
}
}
),
@ -97,6 +109,7 @@ class _MapViewWidget extends State<MapViewWidget> {
language: tabletAppContext.language!,
geoPoints: mapDTO!.points!,
categories: mapDTO!.categories!,
provider: mapDTO!.mapProvider!,
filteredPoints: (value) {
_geoPoints.value = value!;
}),
@ -108,20 +121,9 @@ class _MapViewWidget extends State<MapViewWidget> {
icon: Icon(Icons.directions_boat),
),*/
);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
);
}
getByteIcon(String? source) async {
/*getByteIcon(String? source) async {
if(source != null) {
if(kIsWeb) {
Uint8List fileData = await http.readBytes(Uri.parse(source));
@ -135,15 +137,15 @@ class _MapViewWidget extends State<MapViewWidget> {
final ByteData bytes = await rootBundle.load('assets/icons/marker.png');
selectedMarkerIcon = await getBytesFromAsset(bytes, 25);
}
}
}*/
Uint8List resizeImage(Uint8List data, int width) {
/*Uint8List resizeImage(Uint8List data, int width) {
Uint8List resizedData = data;
IMG.Image img = IMG.decodeImage(data)!;
IMG.Image resized = IMG.copyResize(img, width: width);
resizedData = Uint8List.fromList(IMG.encodeJpg(resized));
return resizedData;
}
}*/
/*Future<void> _goToTheLake() async {
final GoogleMapController controller = await _controller.future;

View File

@ -6,10 +6,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:manager_api/api.dart';
import 'package:provider/provider.dart';
import 'package:tablet_app/Components/loading_common.dart';
import 'package:tablet_app/Helpers/ImageCustomProvider.dart';
import 'package:tablet_app/Models/map-marker.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/Screens/Agenda/agenda_view.dart';
import 'package:tablet_app/Screens/MainView/main_view.dart';
import 'package:tablet_app/Screens/Map/map_context.dart';
import 'package:tablet_app/Screens/Map/map_view.dart';
import 'package:tablet_app/Screens/PDF/pdf_view.dart';
@ -68,7 +70,22 @@ class _MenuView extends State<MenuView> {
longitude: null,
title: '',
description: '')),
child: MapViewWidget(section: selectedSection) /*FutureBuilder(
child: FutureBuilder(
future: getByteIcons(selectedSection!),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MapViewWidget(section: selectedSection!, icons: snapshot.data);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
child: LoadingCommon()
)
);
}
}
) /*FutureBuilder(
future: _url,
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
? WebViewWidget(url: snapshot.data,)

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:manager_api/api.dart';
import 'package:provider/provider.dart';
import 'package:tablet_app/Models/map-marker.dart';
import 'package:tablet_app/Screens/Map/map_context.dart';
@ -269,7 +270,7 @@ class _PreviousViewWidget extends State<PreviousViewWidget> with TickerProviderS
longitude: null,
title: '',
description: '')),
child: MapViewWidget() /*FutureBuilder(
child: MapViewWidget(section: SectionDTO(), icons: []) /*FutureBuilder(
future: _url,
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
? WebViewWidget(url: snapshot.data,)