;
}
}
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:weather_app/logic/cubits/weather/weather_cubit.dart';
import 'package:weather_app/presentation/widgets/city_part.dart';
import '../widgets/temperature.dart';
import '../widgets/weather_menu.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State createState() => _HomeScreenState();
}
class _HomeScreenState extends State {
@override
void initState() {
super.initState();
_getWeather('tashkent');
}
void _getWeather(String city) {
context.read().getWeather(city);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocConsumer, WeatherState>(
listener: (context, state) async {
if (state is WeatherError) {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Error'),
content: Text(state.message),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'))
],
),
);
if (state.message.toLowerCase().contains('not found')) {
_getWeather('tashkent');
}
}
},
builder: (context, state) {
if (state is WeatherInitial) {
return const Center(
child: Text('Select a city'),
);
}
if (state is WeatherLoading) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (state is WeatherLoaded) {
final weather = state.weather
Do'stlaringiz bilan baham: |