refactor(ui): update tags in DeviceLogsScreen

This commit is contained in:
anhtunz
2024-12-27 10:59:47 +07:00
parent 70e3ed8978
commit 178a00f5ba
11 changed files with 373 additions and 58 deletions

View File

@@ -16,6 +16,10 @@ class MapBloc extends BlocBase {
@override
void dispose() {}
final mapTheme = StreamController<String>.broadcast();
StreamSink<String> get sinkMapTheme => mapTheme.sink;
Stream<String> get streamMapTheme => mapTheme.stream;
final mapType = StreamController<MapType>.broadcast();
StreamSink<MapType> get sinkMapType => mapType.sink;
Stream<MapType> get streamMapType => mapType.stream;

View File

@@ -14,6 +14,8 @@ import 'package:sfm_app/product/constant/icon/icon_constants.dart';
import 'package:sfm_app/product/permission/location_permission.dart';
import 'package:sfm_app/product/services/api_services.dart';
import '../../product/constant/enums/app_theme_enums.dart';
class MapScreen extends StatefulWidget {
const MapScreen({super.key});
@@ -51,13 +53,20 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
LatLng myLocation = const LatLng(213761, 123123);
Position? position;
bool isAllowLocationPermission = false;
String themeMode = "";
@override
void initState() {
super.initState();
mapBloc = BlocProvider.of(context);
checkTheme();
_loadIcons();
getAllMarkers();
clusterManager = _initClusterManager();
DefaultAssetBundle.of(context)
.loadString("assets/map_themes/maps_dark_theme.json")
.then(
(value) => {themeMode = value},
);
}
@override
@@ -78,36 +87,41 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
return StreamBuilder<List<LatLng>>(
stream: mapBloc.streamPolylines,
builder: (context, polylinesSnapshot) {
return GoogleMap(
initialCameraPosition: _myPosition,
mapType: mapType,
onMapCreated: (GoogleMapController controller) {
if (!_controller.isCompleted) {
_controller.complete(controller);
}
streamController.sink.add(controller);
clusterManager.setMapId(controller.mapId);
},
markers: markerSnapshot.data ?? markersAll
..addAll(markers),
zoomControlsEnabled: true,
myLocationEnabled: true,
mapToolbarEnabled: false,
onCameraMove: (position) {
clusterManager.onCameraMove(position);
},
onCameraIdle: () {
clusterManager.updateMap();
},
polylines: {
Polyline(
polylineId: const PolylineId('router'),
points: polylinesSnapshot.data ?? [],
color: Colors.deepPurpleAccent,
width: 8,
),
},
);
return StreamBuilder<String>(
stream: mapBloc.streamMapTheme,
builder: (context, mapThemeSnapshot) {
return GoogleMap(
initialCameraPosition: _myPosition,
mapType: mapType,
onMapCreated: (GoogleMapController controller) {
controller.setMapStyle(themeMode);
if (!_controller.isCompleted) {
_controller.complete(controller);
}
streamController.sink.add(controller);
clusterManager.setMapId(controller.mapId);
},
markers: markerSnapshot.data ?? markersAll
..addAll(markers),
zoomControlsEnabled: true,
myLocationEnabled: true,
mapToolbarEnabled: false,
onCameraMove: (position) {
clusterManager.onCameraMove(position);
},
onCameraIdle: () {
clusterManager.updateMap();
},
polylines: {
Polyline(
polylineId: const PolylineId('router'),
points: polylinesSnapshot.data ?? [],
color: Colors.deepPurpleAccent,
width: 8,
),
},
);
});
},
);
},
@@ -117,6 +131,22 @@ class _MapScreenState extends State<MapScreen> with WidgetsBindingObserver {
);
}
void checkTheme() async {
String theme = await apiServices.checkTheme();
if (theme == AppThemes.LIGHT.name) {
getThemeMode('assets/map_themes/maps_light_theme.json');
} else {
getThemeMode('assets/map_themes/maps_dark_theme.json');
}
}
void getThemeMode(String path) {
DefaultAssetBundle.of(context)
.loadString(path)
.then((value) => {themeMode = value});
mapBloc.sinkMapTheme.add(themeMode);
}
Future<void> _loadIcons() async {
List<Future<BitmapDescriptor>> iconFutures = imageAssets.map((asset) {
return BitmapDescriptor.fromAssetImage(const ImageConfiguration(), asset);