Fix markers

This commit is contained in:
Yoshi 2024-08-18 14:08:54 +03:00
parent 8ed047a1aa
commit 383fb24881
4 changed files with 361 additions and 315 deletions

2
.gitignore vendored
View file

@ -42,5 +42,3 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
/lib/secret_key.dart

View file

@ -85,7 +85,9 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
child: ScaffoldMessenger(
key: globalKey,
child: Scaffold(
appBar: AppBar(
appBar: tabIndex == 2
? null
: AppBar(
centerTitle: true,
automaticallyImplyLeading: false,
leading: switch (tabIndex) {
@ -116,7 +118,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
),
);
},
optionsBuilder: (TextEditingValue textEditingValue) {
optionsBuilder:
(TextEditingValue textEditingValue) {
if (textEditingValue.text.isEmpty) {
return const Iterable<Result>.empty();
}
@ -152,7 +155,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
itemBuilder:
(BuildContext context, int index) {
final Result option =
options.elementAt(index);
return InkWell(
@ -187,7 +191,9 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
: '$city' ', $district'
: settings.location
? 'search'.tr
: (isar.locationCaches.where().findAllSync())
: (isar.locationCaches
.where()
.findAllSync())
.isNotEmpty
? 'loading'.tr
: 'searchCity'.tr,
@ -199,10 +205,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
'cities'.tr,
style: textStyle,
),
2 => Text(
'map'.tr,
style: textStyle,
),
3 => Text(
'settings_full'.tr,
style: textStyle,

View file

@ -1,17 +1,19 @@
import 'dart:io';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:flutter_map_cache/flutter_map_cache.dart';
import 'package:get/get.dart';
import 'package:iconsax_plus/iconsax_plus.dart';
import 'package:latlong2/latlong.dart';
import 'package:path_provider/path_provider.dart';
import 'package:rain/app/controller/controller.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:rain/app/data/weather.dart';
import 'package:rain/app/modules/cards/view/info_weather_card.dart';
import 'package:rain/app/modules/cards/widgets/create_card_weather.dart';
import 'package:rain/secret_key.dart';
import 'package:rain/app/modules/cards/widgets/weather_card_container.dart';
import 'package:rain/app/widgets/status/status_weather.dart';
class MapWeather extends StatefulWidget {
const MapWeather({super.key});
@ -21,56 +23,163 @@ class MapWeather extends StatefulWidget {
}
class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
late final _animatedMapController = AnimatedMapController(vsync: this);
late final AnimatedMapController _animatedMapController =
AnimatedMapController(vsync: this);
final weatherController = Get.put(WeatherController());
bool isDarkMode = Get.theme.brightness == Brightness.dark;
final statusWeather = StatusWeather();
final Future<CacheStore> _cacheStoreFuture = _getCacheStore();
final bool _isDarkMode = Get.theme.brightness == Brightness.dark;
WeatherCard? _selectedWeatherCard;
bool _isCardVisible = false;
double _cardBottomPosition = -200;
static Future<CacheStore> _getCacheStore() async {
final dir = await getTemporaryDirectory();
return FileCacheStore('${dir.path}${Platform.pathSeparator}MapTiles');
}
@override
Widget build(BuildContext context) {
final mainLocation = weatherController.location;
// final mainWeather = weatherController.mainWeather;
// final weatherCard = WeatherCard.fromJson({}
// ..addAll(mainWeather.toJson())
// ..addAll(mainLocation.toJson()));
void _onMarkerTap(WeatherCard weatherCard) {
setState(() {
_selectedWeatherCard = weatherCard;
_cardBottomPosition = 0;
_isCardVisible = true;
});
}
Widget darkModeTilesContainerBuilder(
BuildContext context,
Widget tilesContainer,
) {
return ColorFiltered(
colorFilter: const ColorFilter.matrix(<double>[
-0.2126, -0.7152, -0.0722, 0, 255, // Red channel
-0.2126, -0.7152, -0.0722, 0, 255, // Green channel
-0.2126, -0.7152, -0.0722, 0, 255, // Blue channel
0, 0, 0, 1, 0, // Alpha channel
]),
child: tilesContainer,
void _hideCard() {
setState(() {
_cardBottomPosition = -200;
});
Future.delayed(const Duration(milliseconds: 300), () {
setState(() {
_isCardVisible = false;
});
});
}
Marker _buildMainLocationMarker(
WeatherCard weatherCard, int hourOfDay, int dayOfNow) {
return Marker(
height: 40,
width: 40,
point: LatLng(weatherCard.lat!, weatherCard.lon!),
child: GestureDetector(
onTap: () => _onMarkerTap(weatherCard),
child: Container(
decoration: BoxDecoration(
color: context.theme.colorScheme.onSecondary,
shape: BoxShape.circle,
),
child: Image.asset(
statusWeather.getImageNow(
weatherCard.weathercode![hourOfDay],
weatherCard.time![hourOfDay],
weatherCard.sunrise![dayOfNow],
weatherCard.sunset![dayOfNow],
),
scale: 15,
),
),
),
);
}
Widget openStreetMapTileLayer(CacheStore cacheStore) {
Marker _buildCardMarker(WeatherCard weatherCardList) {
return Marker(
height: 40,
width: 40,
point: LatLng(weatherCardList.lat!, weatherCardList.lon!),
child: GestureDetector(
onTap: () => _onMarkerTap(weatherCardList),
child: Container(
decoration: BoxDecoration(
color: context.theme.colorScheme.onSecondary,
shape: BoxShape.circle,
),
child: Image.asset(
statusWeather.getImageNow(
weatherCardList.weathercode![weatherController.getTime(
weatherCardList.time!, weatherCardList.timezone!)],
weatherCardList.time![weatherController.getTime(
weatherCardList.time!, weatherCardList.timezone!)],
weatherCardList.sunrise![weatherController.getDay(
weatherCardList.timeDaily!, weatherCardList.timezone!)],
weatherCardList.sunset![weatherController.getDay(
weatherCardList.timeDaily!, weatherCardList.timezone!)],
),
scale: 15,
),
),
),
);
}
Widget _buildMapTileLayer(CacheStore cacheStore) {
return TileLayer(
urlTemplate:
'https://api.mapbox.com/styles/v1/yoshimok/clzvnt6ae000s01qsh52veh8f/tiles/256/{z}/{x}/{y}@2x?access_token=$accessToken',
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.darkmoonight.rain',
tileProvider: CachedTileProvider(
store: cacheStore,
maxStale: const Duration(days: 30),
));
),
);
}
Widget _buildWeatherCard() {
return AnimatedPositioned(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
left: 0,
right: 0,
bottom: _cardBottomPosition,
child: AnimatedOpacity(
opacity: _isCardVisible ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: _isCardVisible
? GestureDetector(
onTap: () => Get.to(
() => InfoWeatherCard(weatherCard: _selectedWeatherCard!),
transition: Transition.downToUp,
),
child: WeatherCardContainer(
time: _selectedWeatherCard!.time!,
timeDaily: _selectedWeatherCard!.timeDaily!,
timeDay: _selectedWeatherCard!.sunrise!,
timeNight: _selectedWeatherCard!.sunset!,
weather: _selectedWeatherCard!.weathercode!,
degree: _selectedWeatherCard!.temperature2M!,
district: _selectedWeatherCard!.district!,
city: _selectedWeatherCard!.city!,
timezone: _selectedWeatherCard!.timezone!,
),
)
: const SizedBox.shrink(),
),
);
}
@override
Widget build(BuildContext context) {
final mainLocation = weatherController.location;
final mainWeather = weatherController.mainWeather;
final hourOfDay = weatherController.hourOfDay.value;
final dayOfNow = weatherController.dayOfNow.value;
return FutureBuilder<CacheStore>(
future: _cacheStoreFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
}
final cacheStore = snapshot.data!;
return FlutterMap(
mapController: _animatedMapController.mapController,
options: MapOptions(
@ -83,6 +192,7 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
const LatLng(90, 180),
),
),
onTap: (_, __) => _hideCard(),
onLongPress: (tapPosition, point) => showModalBottomSheet(
context: context,
isScrollControlled: true,
@ -94,101 +204,50 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
),
),
children: [
isDarkMode
? darkModeTilesContainerBuilder(
context, openStreetMapTileLayer(cacheStore))
: openStreetMapTileLayer(cacheStore),
if (_isDarkMode)
ColorFiltered(
colorFilter: const ColorFilter.matrix(<double>[
-0.2126, -0.7152, -0.0722, 0, 255, // Red channel
-0.2126, -0.7152, -0.0722, 0, 255, // Green channel
-0.2126, -0.7152, -0.0722, 0, 255, // Blue channel
0, 0, 0, 1, 0, // Alpha channel
]),
child: _buildMapTileLayer(cacheStore),
)
else
_buildMapTileLayer(cacheStore),
RichAttributionWidget(
animationConfig: const ScaleRAWA(),
attributions: [
TextSourceAttribution(
'Mapbox contributors',
'OpenStreetMap contributors',
onTap: () => weatherController
.urlLauncher('https://www.mapbox.com/legal/tos'),
.urlLauncher('https://openstreetmap.org/copyright'),
),
],
),
Obx(
() {
var weatherCards = weatherController.weatherCards.toList();
Obx(() {
final mainMarker = _buildMainLocationMarker(
WeatherCard.fromJson({
...mainWeather.toJson(),
...mainLocation.toJson(),
}),
hourOfDay,
dayOfNow,
);
final cardMarkers = weatherController.weatherCards
.map((weatherCardList) => _buildCardMarker(weatherCardList))
.toList();
return MarkerLayer(
markers: [
Marker(
point: LatLng(mainLocation.lat!, mainLocation.lon!),
child: GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
color:
context.theme.colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(10),
),
child: Icon(
IconsaxPlusBold.home,
color: context
.theme.colorScheme.onSecondaryContainer,
),
),
),
),
...weatherCards.map(
(weatherCardList) => Marker(
width: 35,
height: 35,
point: LatLng(
weatherCardList.lat!, weatherCardList.lon!),
child: GestureDetector(
onTap: () {},
child: Container(
decoration: BoxDecoration(
color: context
.theme.colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
IconsaxPlusBold.location,
color: Colors.red,
),
),
),
),
)
markers: [mainMarker, ...cardMarkers],
);
}),
_buildWeatherCard(),
],
);
},
),
// Positioned(
// left: 0,
// right: 0,
// bottom: 0,
// child: GestureDetector(
// onTap: () => Get.to(
// () => InfoWeatherCard(
// weatherCard: weatherCard,
// ),
// transition: Transition.downToUp,
// ),
// child: WeatherCardContainer(
// time: mainWeather.time!,
// timeDaily: mainWeather.timeDaily!,
// timeDay: mainWeather.sunrise!,
// timeNight: mainWeather.sunset!,
// weather: mainWeather.weathercode!,
// degree: mainWeather.temperature2M!,
// district: mainLocation.district!,
// city: mainLocation.city!,
// timezone: mainWeather.timezone!,
// ),
// ),
// )
],
);
}
if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
}
return const Center(child: CircularProgressIndicator());
},
);
}
}

View file

@ -15,7 +15,6 @@ import 'package:rain/app/modules/settings/widgets/setting_card.dart';
import 'package:rain/main.dart';
import 'package:rain/theme/theme_controller.dart';
import 'package:rain/utils/color_converter.dart';
import 'package:url_launcher/url_launcher.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@ -978,27 +977,15 @@ class _SettingsPageState extends State<SettingsPage> {
elevation: 4,
icon: const Icon(LineAwesomeIcons.discord),
text: 'Discord',
onPressed: () async {
final Uri url = Uri.parse(
'https://discord.gg/JMMa9aHh8f');
if (!await launchUrl(url,
mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
},
onPressed: () => weatherController.urlLauncher(
'https://discord.gg/JMMa9aHh8f'),
),
SettingCard(
elevation: 4,
icon: const Icon(LineAwesomeIcons.telegram),
text: 'Telegram',
onPressed: () async {
final Uri url =
Uri.parse('https://t.me/darkmoonightX');
if (!await launchUrl(url,
mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
},
onPressed: () => weatherController
.urlLauncher('https://t.me/darkmoonightX'),
),
const Gap(10),
],