Flutter bloc cubit test knowdge - Flutter bloc cubit test knowdge

Overview

Flutter Bloc Simple Api

This project is using weather api for featch data and display based on user input data

Weather Cubit

class WeatherCubit extends Cubit<WeatherState> {
  //_weatherReposotory object for fetch data from Reposotory
  final WeatherReposotory _weatherReposotory;

  WeatherCubit(
    this._weatherReposotory,
  ) : super(const WeatherInitial());

  //getWeather function use for get weather data from Reposotory.
  Future<void> getWeather(String cityName) async {
    //notify frontend to Weather loading state
    emit(const WeatherLoading());

    try {
      final weather = await _weatherReposotory.getWeatherLocationData(cityName);
      //notify frontend to Weather loaded state with weather data
      emit(WeatherLoaded(weather, cityName));
    } on SocketException {
      //notify frontend to WeatherError state with SocketException
      emit(const WeatherError("400"));
    } catch (e) {
      final failure = e as Failure;
      //notify frontend to WeatherError state with failure message
      emit(WeatherError(failure.message));
    }
  }
}

Weather Repository

class WeatherReposotory {
  //api object use for fetch data from api
  final WeatherApi api;
  WeatherReposotory({required this.api});

  //getWeatherLocationData function is asyncrones method and using fetch data and return data to cubit
  Future<dynamic> getWeatherLocationData(String cityName) async {
    //rawWeather get response from api using user enter city name
    final Response rawWeather = await api.getWeatherRawData(cityName);
    if (rawWeather.statusCode == 200) {
      //decode jason response body and map body data
      Map<String, dynamic> weatherMap = jsonDecode(rawWeather.body);
      //Map cityname and temp using weather model and return weather data
      var weather = Weather.fromJson(weatherMap);
      return weather;
    } else {
      throw const Failure(message: '404');
    }
  }
}

Weather Api

class WeatherApi {
  //base url. url end point
  static const String _baseUrl =
      "http://api.openweathermap.org/data/2.5/weather?q=";

  //Api key
  static const String _apiKey = "01cc8328d04c516c03c84af29cd9c0d9";
  final http.Client _client;

  WeatherApi({http.Client? client}) : _client = client ?? http.Client();

  void dispose() {
    _client.close();
  }

  //Fectch weather data from api
  Future<dynamic> getWeatherRawData(String cityName) async {
    final url = '$_baseUrl$cityName&appid=$_apiKey';

    final response = await _client.post(
      Uri.parse(url),
    );
    return response;
  }
}
```# flutter_bloc_cubit_test_knowdge
You might also like...

๐ŸŒฐ๐ŸŒฐ [BLOC_PATTERN] [RXDART] [STREAM] ๐Ÿ„๐Ÿ„ Simple auth app flutter, server node.js, BLoC pattern, RxDart ๐Ÿ๐Ÿ Functionalities: LOGIN, REGISTER, CHANGE PASSWORD, CHANGE AVATAR, FORGOT PASSWORD. Pure rxdart BLoC pattern. BLoC pattern without library.

๐ŸŒฐ๐ŸŒฐ [BLOC_PATTERN] [RXDART] [STREAM] ๐Ÿ„๐Ÿ„ Simple auth app flutter, server node.js, BLoC pattern, RxDart ๐Ÿ๐Ÿ Functionalities: LOGIN, REGISTER, CHANGE PASSWORD, CHANGE AVATAR, FORGOT PASSWORD. Pure rxdart BLoC pattern. BLoC pattern without library.

node_auth #node-auth-flutter-BLoC-pattern-RxDart โ„๏ธ โ„๏ธ BLoC pattern rxdart stream ๐Ÿ‹ ๐Ÿ‹ Simple auth app flutter, server node.js, BLoC pattern, RxDart

Dec 29, 2022

Integration Test Preview allows tests on multiple screen sizes in a single e2e test run.

Integration Test Preview allows tests on multiple screen sizes in a single e2e test run.

Integration Test Preview has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage (using Android and iOS pl

Aug 23, 2022

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

Jan 5, 2022

Flutter app using Cubit & API

fluttermasterproject A new Flutter master project using API & Cubit. Getting Started This project is a starting point for a Flutter application. A few

Apr 30, 2022

Cubit is a lightweight state management solution

Cubit is a lightweight state management solution

Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states.

Nov 23, 2022

This application displays the characters of the series Breaking Bad, has been used Cubit state and API .

breaking_bad A new Flutter project using bloc. Getting Started This project is a starting point for bloc state_management. A few resources to get you

Dec 24, 2021

Movies application (Cubit, Android, iOS, macOS, Web, Windows)

Movies App (Cubit) Movies Application Platforms 1 - Android 2 - iOS 3 - macOS 4 - Web 5 - Windows Libraries & Tools Flutter 3.0.1 โ€ข channel stable Da

Jun 7, 2022
Owner
Waruna Kaushalya
Waruna Kaushalya
Flutter Viral News App using : Flutter + Rest Api + Bloc / Cubit

Intro Viral News App on Flutter. The tech used: Flutter widgets + Flutter Bloc / Cubit + Rest Api Check the screenshot : P.S Make sure to upgrade your

Ihab Zaidi 8 Nov 2, 2022
Building a simple Flutter app for understanding the BLoC State Management including: Cubit, Managing Route & showSnackBar.

Building a simple Flutter app for understanding the BLoC State Management including: Cubit, Managing Route & showSnackBar.

TAD 8 Dec 3, 2022
Flutter boilerplate: support Android, iOS, Web, Mac, Linux, Window with bloc(cubit) state management

Flutter boilerplate: support Android, iOS, Web, Mac, Linux, Window with bloc(cubit) state management, dynamic theme, localization, environment (.env), logger, navigation (go_router), responsiveness (mobile, tablet, desktop), lint, unit/widget/integration test and more ...

Bumbii Co., Ltd 34 Dec 29, 2022
Flutter boilerplate: support Android, iOS, Web, Mac, Linux, Window with bloc(cubit)

Flutter boilerplate: support Android, iOS, Web, Mac, Linux, Window with bloc(cubit) state management, dynamic theme, localization, environment (.env), logger, navigation (go_router), responsiveness (mobile, tablet, desktop), lint, and unit/integration test.

Bumbii Co., Ltd 34 Dec 29, 2022
Building a simple Flutter app * Switch Theme * for understanding the BLoC State Management including: Cubit Communications with StreamSubscription & Managing Route.

Building a simple Flutter app * Switch Theme * for understanding the BLoC State Management including: Cubit Communications with StreamSubscription & Managing Route.

TAD 1 Oct 3, 2022
๐Ÿ’ป Flutter clean architecture using the bloc & cubit library for state management

Egymation ?? ยท This application was developed using a well-defined and decoupled architecture, following TDD (test-driven programming) as a working me

Mohaned Zekry 3 Nov 21, 2022
๐Ÿš€ User management app built in flutter using clean architecture, MVVM, get it, dio, RxDart, bloc, cubit, getX and provider

?? Go Rest app In this project, we are going to build a user management app using Flutter. We have used the Go REST API to make HTTP request methods.

Sina 99 Aug 14, 2023
sample project for bloc & cubit

bloc & cubit sample Sample project for bloc & cubit Getting Started This project is a starting point for a Flutter application. A few resources to get

null 0 Dec 29, 2021
FlutterAgoraFirebaseVideoCall (Agora RTC, Bloc Pattern, Cubit, Firestore, Cloud Function, FCM)

Flutter Agora Fully Functional Video Call module Tech Stack Client: Dart, Flutter Server: Firebase firestore, Google cloud functions Techniques: *BloC

Youssef Elshiaty 39 Dec 16, 2022
Integration test - Copy of the official Flutter integration test plugin

integration_test This package enables self-driving testing of Flutter code on de

null 0 Jan 5, 2022