|
}
}
import 'package:flutter/material.dart'
|
səhifə | 4/9 | tarix | 17.06.2023 | ölçüsü | 1,58 Mb. | | #132099 |
| “Mobil ilovalarni ishlab chiqish” fanidan
;
}
}
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
Dostları ilə paylaş: |
|
|