“Mobil ilovalarni ishlab chiqish” fanidan


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


Download 1.58 Mb.
bet4/9
Sana14.04.2023
Hajmi1.58 Mb.
#1358106
1   2   3   4   5   6   7   8   9
Bog'liq
1-lab mobil

;
}
}

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

Download 1.58 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling