Untitled
unknown
plain_text
5 months ago
3.4 kB
2
Indexable
import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import '../../../../core/extensions/context_extensions.dart'; import '../../../../core/utils/core_utils.dart'; import '../bloc/find_bloc.dart'; import '../refactors/maps_header.dart'; import 'package:flutter/material.dart'; import '../refactors/maps_page_view.dart'; class MapsScreen extends StatefulWidget { const MapsScreen({super.key}); @override State<MapsScreen> createState() => _MapsScreenState(); } class _MapsScreenState extends State<MapsScreen> with SingleTickerProviderStateMixin { late TabController tabController; final Completer<GoogleMapController> gController = Completer(); @override void initState() { tabController = TabController(length: 3, vsync: this); tabController.addListener(() { setState(() {}); }); _handlerRefresh(); super.initState(); } Future<void> _handlerRefresh() async { context.read<FindBloc>().add(const GetChargeStationsEvent()); } @override void dispose() { tabController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( body: BlocConsumer<FindBloc, FindState>( listener: (context, state) { if (state is FindError) { CoreUtils.showSnackBar(context, state.message); } else if (state is GetFavoriteChargeStationsLoaded) { context.chargeStationsProvider .initFavoriteChargeStations(state.favoriteChargeStations); } else if (state is ChargeStationsLoaded) { context.chargeStationsProvider .initChargeStations(state.chargeStations); context.read<FindBloc>().add(LoadMarkersEvent( state.chargeStations, )); } else if (state is MarkersLoaded) { context.chargeStationsProvider.initMarkers(state.markers); context .read<FindBloc>() .add(GetFavoriteChargeStationsEvent(context.currentUser!.id)); } else if (state is AddFavoriteChargeStationsSuccess) { context.chargeStationsProvider .addFavoriteChargeStations(state.chargerStationId); CoreUtils.showSnackBar(context, 'Added to favorites'); } else if (state is DeleteFavoriteChargeStationsSuccess) { context.chargeStationsProvider .deleteFavoriteChargeStations(state.chargerStationId); CoreUtils.showSnackBar(context, 'Removed from favorites'); } else if (state is FilteredChargeStationsLoaded) { debugPrint(state.filteredChargeStations.toString()); context.chargeStationsProvider .setFilterListChargeStations(state.filteredChargeStations); } }, builder: (context, state) { return Stack( children: [ MapsPageView( handleRefresh: _handlerRefresh, tabController: tabController, gController: gController, state: state, ), MapsHeader(controller: tabController), ], ); }, ), ); } }
Editor is loading...
Leave a Comment