Rain/lib/app/ui/places/widgets/place_card.dart

144 lines
4.8 KiB
Dart
Raw Normal View History

2023-06-17 20:57:57 +03:00
import 'package:flutter/material.dart';
2024-08-04 11:48:25 +03:00
import 'package:gap/gap.dart';
2023-06-17 20:57:57 +03:00
import 'package:get/get.dart';
import 'package:rain/app/controller/controller.dart';
2024-09-06 22:07:50 +03:00
import 'package:rain/app/ui/widgets/weather/status/status_weather.dart';
import 'package:rain/app/ui/widgets/weather/status/status_data.dart';
2023-06-17 20:57:57 +03:00
import 'package:timezone/standalone.dart' as tz;
2024-09-06 22:07:50 +03:00
class PlaceCard extends StatefulWidget {
const PlaceCard({
2023-06-17 20:57:57 +03:00
super.key,
required this.time,
required this.weather,
required this.degree,
required this.district,
required this.city,
required this.timezone,
required this.timeDay,
required this.timeNight,
required this.timeDaily,
});
final List<String> time;
final List<String> timeDay;
final List<String> timeNight;
final List<DateTime> timeDaily;
final String district;
final String city;
final List<int> weather;
final List<double> degree;
final String timezone;
@override
2024-09-06 22:07:50 +03:00
State<PlaceCard> createState() => _PlaceCardState();
2023-06-17 20:57:57 +03:00
}
2024-09-06 22:07:50 +03:00
class _PlaceCardState extends State<PlaceCard> {
2023-07-15 21:51:32 +03:00
final statusWeather = StatusWeather();
final statusData = StatusData();
2023-09-01 20:18:40 +03:00
final weatherController = Get.put(WeatherController());
2023-06-17 20:57:57 +03:00
@override
Widget build(BuildContext context) {
2023-07-10 21:33:43 +03:00
return Card(
2023-06-17 20:57:57 +03:00
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
2023-07-10 21:33:43 +03:00
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 20),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
2025-03-15 23:40:48 +03:00
statusData.getDegree(
widget
.degree[weatherController.getTime(
widget.time,
widget.timezone,
)]
.round()
.toInt(),
),
2023-07-10 21:33:43 +03:00
style: context.textTheme.titleLarge?.copyWith(
fontSize: 22,
fontWeight: FontWeight.w600,
),
2023-06-17 20:57:57 +03:00
),
2024-08-04 11:48:25 +03:00
const Gap(7),
2023-07-10 21:33:43 +03:00
Text(
2025-03-15 23:40:48 +03:00
statusWeather.getText(
widget.weather[weatherController.getTime(
widget.time,
widget.timezone,
)],
),
2023-07-10 21:33:43 +03:00
style: context.textTheme.titleMedium?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w400,
),
2023-06-17 20:57:57 +03:00
),
2023-07-10 21:33:43 +03:00
],
),
2024-08-04 11:48:25 +03:00
const Gap(10),
2023-07-10 21:33:43 +03:00
Text(
widget.district.isEmpty
? widget.city
: widget.city.isEmpty
2025-03-15 23:40:48 +03:00
? widget.district
: widget.city == widget.district
? widget.city
: '${widget.city}'
', ${widget.district}',
2023-07-10 21:33:43 +03:00
style: context.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w500,
2023-06-17 20:57:57 +03:00
),
),
2024-08-04 11:48:25 +03:00
const Gap(5),
2023-07-10 21:33:43 +03:00
StreamBuilder(
stream: Stream.periodic(const Duration(seconds: 1)),
builder: (context, snapshot) {
return Text(
2023-07-15 21:51:32 +03:00
'${'time'.tr}: ${statusData.getTimeFormatTz(tz.TZDateTime.now(tz.getLocation(widget.timezone)))}',
2023-07-10 21:33:43 +03:00
style: context.textTheme.titleMedium?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w400,
),
);
},
),
],
),
),
2024-08-04 11:48:25 +03:00
const Gap(5),
2023-07-10 21:33:43 +03:00
Image.asset(
2023-07-15 21:51:32 +03:00
statusWeather.getImageNow(
2025-03-15 23:40:48 +03:00
widget.weather[weatherController.getTime(
widget.time,
widget.timezone,
)],
widget.time[weatherController.getTime(
widget.time,
widget.timezone,
)],
widget.timeDay[weatherController.getDay(
widget.timeDaily,
widget.timezone,
)],
widget.timeNight[weatherController.getDay(
widget.timeDaily,
widget.timezone,
)],
),
2023-07-10 21:33:43 +03:00
scale: 6.5,
2023-06-17 20:57:57 +03:00
),
2023-07-10 21:33:43 +03:00
],
),
2023-06-17 20:57:57 +03:00
),
);
}
}