Add markers

This commit is contained in:
Yoshi 2024-08-15 22:39:51 +03:00
parent 6c7da7b28d
commit 8ed047a1aa
10 changed files with 172 additions and 68 deletions

4
.gitignore vendored
View file

@ -41,4 +41,6 @@ app.*.map.json
# Android Studio will place build artifacts here # Android Studio will place build artifacts here
/android/app/debug /android/app/debug
/android/app/profile /android/app/profile
/android/app/release /android/app/release
/lib/secret_key.dart

View file

@ -21,6 +21,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:timezone/data/latest_all.dart' as tz; import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/standalone.dart' as tz; import 'package:timezone/standalone.dart' as tz;
import 'package:timezone/timezone.dart' as tz; import 'package:timezone/timezone.dart' as tz;
import 'package:url_launcher/url_launcher.dart';
import 'package:workmanager/workmanager.dart'; import 'package:workmanager/workmanager.dart';
class WeatherController extends GetxController { class WeatherController extends GetxController {
@ -597,4 +598,11 @@ class WeatherController extends GetxController {
return !value.contains(false); return !value.contains(false);
}); });
} }
void urlLauncher(String uri) async {
final Uri url = Uri.parse(uri);
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
}
} }

View file

@ -157,6 +157,14 @@ class LocationCache {
this.city, this.city,
this.district, this.district,
}); });
Map<String, dynamic> toJson() => {
'id': id,
'lat': lat,
'lon': lon,
'city': city,
'district': district,
};
} }
@collection @collection

View file

@ -124,7 +124,7 @@ const SettingsSchema = CollectionSchema(
getId: _settingsGetId, getId: _settingsGetId,
getLinks: _settingsGetLinks, getLinks: _settingsGetLinks,
attach: _settingsAttach, attach: _settingsAttach,
version: '3.1.7', version: '3.1.8',
); );
int _settingsEstimateSize( int _settingsEstimateSize(
@ -3047,7 +3047,7 @@ const MainWeatherCacheSchema = CollectionSchema(
getId: _mainWeatherCacheGetId, getId: _mainWeatherCacheGetId,
getLinks: _mainWeatherCacheGetLinks, getLinks: _mainWeatherCacheGetLinks,
attach: _mainWeatherCacheAttach, attach: _mainWeatherCacheAttach,
version: '3.1.7', version: '3.1.8',
); );
int _mainWeatherCacheEstimateSize( int _mainWeatherCacheEstimateSize(
@ -10770,7 +10770,7 @@ const LocationCacheSchema = CollectionSchema(
getId: _locationCacheGetId, getId: _locationCacheGetId,
getLinks: _locationCacheGetLinks, getLinks: _locationCacheGetLinks,
attach: _locationCacheAttach, attach: _locationCacheAttach,
version: '3.1.7', version: '3.1.8',
); );
int _locationCacheEstimateSize( int _locationCacheEstimateSize(
@ -11869,7 +11869,7 @@ const WeatherCardSchema = CollectionSchema(
getId: _weatherCardGetId, getId: _weatherCardGetId,
getLinks: _weatherCardGetLinks, getLinks: _weatherCardGetLinks,
attach: _weatherCardAttach, attach: _weatherCardAttach,
version: '3.1.7', version: '3.1.8',
); );
int _weatherCardEstimateSize( int _weatherCardEstimateSize(

View file

@ -9,7 +9,13 @@ import 'package:rain/app/widgets/text_form.dart';
import 'package:rain/main.dart'; import 'package:rain/main.dart';
class CreateWeatherCard extends StatefulWidget { class CreateWeatherCard extends StatefulWidget {
const CreateWeatherCard({super.key}); const CreateWeatherCard({
super.key,
this.latitude,
this.longitude,
});
final String? latitude;
final String? longitude;
@override @override
State<CreateWeatherCard> createState() => _CreateWeatherCardState(); State<CreateWeatherCard> createState() => _CreateWeatherCardState();
@ -21,11 +27,11 @@ class _CreateWeatherCardState extends State<CreateWeatherCard>
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
final _focusNode = FocusNode(); final _focusNode = FocusNode();
final weatherController = Get.put(WeatherController()); final weatherController = Get.put(WeatherController());
final _controller = TextEditingController(); late final TextEditingController _controller = TextEditingController();
final _controllerLat = TextEditingController(); late TextEditingController _controllerLat = TextEditingController();
final _controllerLon = TextEditingController(); late TextEditingController _controllerLon = TextEditingController();
final _controllerCity = TextEditingController(); late final TextEditingController _controllerCity = TextEditingController();
final _controllerDistrict = TextEditingController(); late final TextEditingController _controllerDistrict = TextEditingController();
late AnimationController _animationController; late AnimationController _animationController;
late Animation<double> _animation; late Animation<double> _animation;
@ -33,6 +39,10 @@ class _CreateWeatherCardState extends State<CreateWeatherCard>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.latitude != null && widget.longitude != null) {
_controllerLat = TextEditingController(text: widget.latitude);
_controllerLon = TextEditingController(text: widget.longitude);
}
_animationController = AnimationController( _animationController = AnimationController(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
vsync: this, vsync: this,

View file

@ -1,15 +1,17 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_animations/flutter_map_animations.dart'; import 'package:flutter_map_animations/flutter_map_animations.dart';
import 'package:flutter_map_cache/flutter_map_cache.dart'; import 'package:flutter_map_cache/flutter_map_cache.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:iconsax_plus/iconsax_plus.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:rain/app/controller/controller.dart'; import 'package:rain/app/controller/controller.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.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:dio_cache_interceptor_file_store/dio_cache_interceptor_file_store.dart';
import 'package:rain/app/modules/cards/widgets/create_card_weather.dart';
import 'package:rain/secret_key.dart';
class MapWeather extends StatefulWidget { class MapWeather extends StatefulWidget {
const MapWeather({super.key}); const MapWeather({super.key});
@ -21,6 +23,7 @@ class MapWeather extends StatefulWidget {
class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin { class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
late final _animatedMapController = AnimatedMapController(vsync: this); late final _animatedMapController = AnimatedMapController(vsync: this);
final weatherController = Get.put(WeatherController()); final weatherController = Get.put(WeatherController());
bool isDarkMode = Get.theme.brightness == Brightness.dark;
final Future<CacheStore> _cacheStoreFuture = _getCacheStore(); final Future<CacheStore> _cacheStoreFuture = _getCacheStore();
@ -32,7 +35,10 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mainLocation = weatherController.location; final mainLocation = weatherController.location;
bool isDarkMode = Theme.of(context).brightness == Brightness.dark; // final mainWeather = weatherController.mainWeather;
// final weatherCard = WeatherCard.fromJson({}
// ..addAll(mainWeather.toJson())
// ..addAll(mainLocation.toJson()));
Widget darkModeTilesContainerBuilder( Widget darkModeTilesContainerBuilder(
BuildContext context, BuildContext context,
@ -51,7 +57,8 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
Widget openStreetMapTileLayer(CacheStore cacheStore) { Widget openStreetMapTileLayer(CacheStore cacheStore) {
return TileLayer( return TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', urlTemplate:
'https://api.mapbox.com/styles/v1/yoshimok/clzvnt6ae000s01qsh52veh8f/tiles/256/{z}/{x}/{y}@2x?access_token=$accessToken',
userAgentPackageName: 'com.darkmoonight.rain', userAgentPackageName: 'com.darkmoonight.rain',
tileProvider: CachedTileProvider( tileProvider: CachedTileProvider(
store: cacheStore, store: cacheStore,
@ -76,12 +83,104 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
const LatLng(90, 180), const LatLng(90, 180),
), ),
), ),
onLongPress: (tapPosition, point) => showModalBottomSheet(
context: context,
isScrollControlled: true,
enableDrag: false,
builder: (BuildContext context) => CreateWeatherCard(
latitude: '${point.latitude}',
longitude: '${point.longitude}',
),
),
), ),
children: [ children: [
isDarkMode isDarkMode
? darkModeTilesContainerBuilder( ? darkModeTilesContainerBuilder(
context, openStreetMapTileLayer(cacheStore)) context, openStreetMapTileLayer(cacheStore))
: openStreetMapTileLayer(cacheStore) : openStreetMapTileLayer(cacheStore),
RichAttributionWidget(
animationConfig: const ScaleRAWA(),
attributions: [
TextSourceAttribution(
'Mapbox contributors',
onTap: () => weatherController
.urlLauncher('https://www.mapbox.com/legal/tos'),
),
],
),
Obx(
() {
var weatherCards = weatherController.weatherCards.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,
),
),
),
),
)
],
);
},
),
// 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!,
// ),
// ),
// )
], ],
); );
} }

View file

@ -38,13 +38,6 @@ class _SettingsPageState extends State<SettingsPage> {
}); });
} }
void urlLauncher(String uri) async {
final Uri url = Uri.parse(uri);
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
}
@override @override
void initState() { void initState() {
infoVersion(); infoVersion();
@ -933,14 +926,14 @@ class _SettingsPageState extends State<SettingsPage> {
elevation: 4, elevation: 4,
icon: const Icon(IconsaxPlusLinear.card), icon: const Icon(IconsaxPlusLinear.card),
text: 'DonationAlerts', text: 'DonationAlerts',
onPressed: () => urlLauncher( onPressed: () => weatherController.urlLauncher(
'https://www.donationalerts.com/r/darkmoonight'), 'https://www.donationalerts.com/r/darkmoonight'),
), ),
SettingCard( SettingCard(
elevation: 4, elevation: 4,
icon: const Icon(IconsaxPlusLinear.wallet), icon: const Icon(IconsaxPlusLinear.wallet),
text: 'ЮMoney', text: 'ЮMoney',
onPressed: () => urlLauncher( onPressed: () => weatherController.urlLauncher(
'https://yoomoney.ru/to/4100117672775961'), 'https://yoomoney.ru/to/4100117672775961'),
), ),
const Gap(10), const Gap(10),
@ -1051,8 +1044,8 @@ class _SettingsPageState extends State<SettingsPage> {
SettingCard( SettingCard(
icon: const Icon(LineAwesomeIcons.github), icon: const Icon(LineAwesomeIcons.github),
text: '${'project'.tr} GitHub', text: '${'project'.tr} GitHub',
onPressed: () => onPressed: () => weatherController
urlLauncher('https://github.com/darkmoonight/Rain'), .urlLauncher('https://github.com/darkmoonight/Rain'),
), ),
Padding( Padding(
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
@ -1063,7 +1056,8 @@ class _SettingsPageState extends State<SettingsPage> {
overflow: TextOverflow.visible, overflow: TextOverflow.visible,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
onTap: () => urlLauncher('https://open-meteo.com/'), onTap: () =>
weatherController.urlLauncher('https://open-meteo.com/'),
), ),
), ),
const Gap(10), const Gap(10),

View file

@ -132,5 +132,6 @@ class EnUs {
'hourlyVariables': 'Hourly weather variables', 'hourlyVariables': 'Hourly weather variables',
'dailyVariables': 'Daily weather variables', 'dailyVariables': 'Daily weather variables',
'largeElement': 'Large weather display', 'largeElement': 'Large weather display',
'map': 'Map',
}; };
} }

View file

@ -202,10 +202,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: crypto name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.3" version: "3.0.5"
csslib: csslib:
dependency: transitive dependency: transitive
description: description:
@ -266,10 +266,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: dio name: dio
sha256: e17f6b3097b8c51b72c74c9f071a605c47bcc8893839bd66732457a5ebe73714 sha256: "0dfb6b6a1979dac1c1245e17cef824d7b452ea29bd33d3467269f9bef3715fb0"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.5.0+1" version: "5.6.0"
dio_cache_interceptor: dio_cache_interceptor:
dependency: "direct main" dependency: "direct main"
description: description:
@ -290,10 +290,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: dio_web_adapter name: dio_web_adapter
sha256: "36c5b2d79eb17cdae41e974b7a8284fec631651d2a6f39a8a2ff22327e90aeac" sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.1" version: "2.0.0"
dynamic_color: dynamic_color:
dependency: "direct main" dependency: "direct main"
description: description:
@ -412,10 +412,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: flutter_map_animations name: flutter_map_animations
sha256: "826c10a551d9dbb686a8ed9ee8815b974475812c41beb4ce9fe19095fe1c5611" sha256: a2135cd3cf36c07d821efeabb0be31aca380449528af80913c77b158e142eae9
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.0" version: "0.7.1"
flutter_map_cache: flutter_map_cache:
dependency: "direct main" dependency: "direct main"
description: description:
@ -424,14 +424,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.5.1" version: "1.5.1"
flutter_map_cancellable_tile_provider:
dependency: "direct main"
description:
name: flutter_map_cancellable_tile_provider
sha256: "6a2221be8044bd2abfd6ec1de97483fe03f01c7f8b6c2adb4ba160f60d95699a"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
flutter_native_splash: flutter_native_splash:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -686,26 +678,26 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: isar name: isar
sha256: d06cca880885fe016d20a53847ce8605cde595e38de00a613b086fa8fd900790 sha256: e17a9555bc7f22ff26568b8c64d019b4ffa2dc6bd4cb1c8d9b269aefd32e53ad
url: "https://pub.isar-community.dev" url: "https://pub.isar-community.dev"
source: hosted source: hosted
version: "3.1.7" version: "3.1.8"
isar_flutter_libs: isar_flutter_libs:
dependency: "direct main" dependency: "direct main"
description: description:
name: isar_flutter_libs name: isar_flutter_libs
sha256: d5036c0cb92b15025301fb7260e7a7557393c855ed2f9903f2b1fbb56f423bc5 sha256: "78710781e658ce4bff59b3f38c5b2735e899e627f4e926e1221934e77b95231a"
url: "https://pub.isar-community.dev" url: "https://pub.isar-community.dev"
source: hosted source: hosted
version: "3.1.7" version: "3.1.8"
isar_generator: isar_generator:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: isar_generator name: isar_generator
sha256: c88bcdfc4a6407ff9672364bf62330d0314e88753dd0b442179f2f802a5f2179 sha256: "484e73d3b7e81dbd816852fe0b9497333118a9aeb646fd2d349a62cc8980ffe1"
url: "https://pub.isar-community.dev" url: "https://pub.isar-community.dev"
source: hosted source: hosted
version: "3.1.7" version: "3.1.8"
js: js:
dependency: transitive dependency: transitive
description: description:
@ -834,14 +826,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.11.1" version: "0.11.1"
material_floating_search_bar_2:
dependency: "direct main"
description:
name: material_floating_search_bar_2
sha256: ab0c6d209d9491f98dd4c72f2641d0ba1dd35c87effca1f23d8679bece43add0
url: "https://pub.dev"
source: hosted
version: "0.5.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -1123,10 +1107,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: synchronized name: synchronized
sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.1.0+1" version: "3.2.0"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -1211,10 +1195,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_android name: url_launcher_android
sha256: "94d8ad05f44c6d4e2ffe5567ab4d741b82d62e3c8e288cc1fcea45965edf47c9" sha256: f0c73347dfcfa5b3db8bc06e1502668265d39c08f310c29bff4e28eea9699f79
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.3.8" version: "6.3.9"
url_launcher_ios: url_launcher_ios:
dependency: transitive dependency: transitive
description: description:

View file

@ -15,7 +15,7 @@ dependencies:
sdk: flutter sdk: flutter
get: ^4.6.6 get: ^4.6.6
gap: ^3.0.1 gap: ^3.0.1
dio: ^5.5.0+1 dio: ^5.6.0
intl: ^0.19.0 intl: ^0.19.0
shimmer: ^3.0.0 shimmer: ^3.0.0
latlong2: ^0.9.1 latlong2: ^0.9.1
@ -43,19 +43,17 @@ dependencies:
lat_lng_to_timezone: ^0.2.0 lat_lng_to_timezone: ^0.2.0
line_awesome_flutter: ^3.0.1 line_awesome_flutter: ^3.0.1
dio_cache_interceptor: ^3.5.0 dio_cache_interceptor: ^3.5.0
flutter_map_animations: ^0.7.0 flutter_map_animations: ^0.7.1
flutter_hsvcolor_picker: ^1.5.1 flutter_hsvcolor_picker: ^1.5.1
scrollable_positioned_list: ^0.3.8 scrollable_positioned_list: ^0.3.8
flutter_local_notifications: ^17.2.2 flutter_local_notifications: ^17.2.2
material_floating_search_bar_2: ^0.5.0
internet_connection_checker_plus: ^2.5.1 internet_connection_checker_plus: ^2.5.1
dio_cache_interceptor_file_store: ^1.2.2 dio_cache_interceptor_file_store: ^1.2.2
flutter_map_cancellable_tile_provider: ^3.0.0
isar: isar:
version: ^3.1.7 version: ^3.1.8
hosted: https://pub.isar-community.dev/ hosted: https://pub.isar-community.dev/
isar_flutter_libs: isar_flutter_libs:
version: ^3.1.7 version: ^3.1.8
hosted: https://pub.isar-community.dev/ hosted: https://pub.isar-community.dev/
# Uncomment this for publishing FLOSS variant # Uncomment this for publishing FLOSS variant
@ -76,7 +74,7 @@ dev_dependencies:
flutter_native_splash: ^2.4.1 flutter_native_splash: ^2.4.1
flutter_launcher_icons: ^0.13.1 flutter_launcher_icons: ^0.13.1
isar_generator: isar_generator:
version: ^3.1.7 version: ^3.1.8
hosted: https://pub.isar-community.dev/ hosted: https://pub.isar-community.dev/
flutter_launcher_icons: flutter_launcher_icons: