“Mobil ilovalarni ishlab chiqish” fanidan


} } import 'package:flutter/material.dart'



Yüklə 1,58 Mb.
səhifə4/9
tarix17.06.2023
ölçüsü1,58 Mb.
#132099
1   2   3   4   5   6   7   8   9
“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

Yüklə 1,58 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin