From 169d615d6551d6abed821e942f2d152f40c0f17e Mon Sep 17 00:00:00 2001 From: paran01 Date: Fri, 11 Jun 2021 16:39:42 +0530 Subject: [PATCH 1/2] migrate new version null safety version --- lib/data/model/weather.dart | 6 +- lib/main.dart | 2 - lib/pages/weather_search_page.dart | 4 +- pubspec.lock | 111 ++++++++++------------------- pubspec.yaml | 8 +-- 5 files changed, 46 insertions(+), 85 deletions(-) diff --git a/lib/data/model/weather.dart b/lib/data/model/weather.dart index 9bbc9bc..a930b41 100644 --- a/lib/data/model/weather.dart +++ b/lib/data/model/weather.dart @@ -1,12 +1,10 @@ -import 'package:meta/meta.dart'; - class Weather { final String cityName; final double temperatureCelsius; Weather({ - @required this.cityName, - @required this.temperatureCelsius, + required this.cityName, + required this.temperatureCelsius, }); @override diff --git a/lib/main.dart b/lib/main.dart index 2eddea8..8a118e2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,8 +1,6 @@ -import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_cubit_bloc_tutorial/bloc/weather_bloc.dart'; -import 'package:flutter_cubit_bloc_tutorial/cubit/weather_cubit.dart'; import 'package:flutter_cubit_bloc_tutorial/data/weather_repository.dart'; import 'package:flutter_cubit_bloc_tutorial/pages/weather_search_page.dart'; diff --git a/lib/pages/weather_search_page.dart b/lib/pages/weather_search_page.dart index b2b09f8..3809af9 100644 --- a/lib/pages/weather_search_page.dart +++ b/lib/pages/weather_search_page.dart @@ -21,7 +21,7 @@ class _WeatherSearchPageState extends State { child: BlocConsumer( listener: (context, state) { if (state is WeatherError) { - Scaffold.of(context).showSnackBar( + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text(state.message), ), @@ -97,7 +97,7 @@ class CityInputField extends StatelessWidget { } void submitCityName(BuildContext context, String cityName) { - final weatherBloc = context.bloc(); + final weatherBloc = context.read(); weatherBloc.add(GetWeather(cityName)); } } diff --git a/pubspec.lock b/pubspec.lock index 1df295f..72b558a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,76 +1,69 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.6.1" bloc: dependency: "direct main" description: name: bloc url: "https://pub.dartlang.org" source: hosted - version: "6.0.1" + version: "7.0.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" - collection: + version: "1.1.0" + charcode: dependency: transitive description: - name: collection + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" - convert: + version: "1.2.0" + clock: dependency: transitive description: - name: convert + name: clock url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.0" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -82,68 +75,47 @@ packages: name: flutter_bloc url: "https://pub.dartlang.org" source: hosted - version: "6.0.1" + version: "7.0.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.12" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" nested: dependency: transitive description: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" + version: "1.8.0" provider: dependency: transitive description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.3.1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" + version: "5.0.0" sky_engine: dependency: transitive description: flutter @@ -155,63 +127,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.6.1" + version: "2.1.0" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index 923116d..c79ae31 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,17 +18,17 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: '>=2.7.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: sdk: flutter - bloc: ^6.0.1 - flutter_bloc: ^6.0.1 + bloc: ^7.0.0 + flutter_bloc: ^7.0.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.3 dev_dependencies: flutter_test: From e0091b6c46432875f6a206b1cd829a5df5bad02b Mon Sep 17 00:00:00 2001 From: paran01 Date: Fri, 11 Jun 2021 23:23:22 +0530 Subject: [PATCH 2/2] equatable package change --- lib/bloc/weather_bloc.dart | 1 + lib/bloc/weather_event.dart | 5 ++++- lib/bloc/weather_state.dart | 26 +++++++++----------------- lib/cubit/weather_cubit.dart | 1 + lib/cubit/weather_state.dart | 26 +++++++++----------------- lib/data/model/weather.dart | 15 ++++----------- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 8 files changed, 36 insertions(+), 46 deletions(-) diff --git a/lib/bloc/weather_bloc.dart b/lib/bloc/weather_bloc.dart index 604e734..ba674bc 100644 --- a/lib/bloc/weather_bloc.dart +++ b/lib/bloc/weather_bloc.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; import 'package:flutter_cubit_bloc_tutorial/data/model/weather.dart'; import 'package:flutter_cubit_bloc_tutorial/data/weather_repository.dart'; import 'package:meta/meta.dart'; diff --git a/lib/bloc/weather_event.dart b/lib/bloc/weather_event.dart index d097ecc..8b62217 100644 --- a/lib/bloc/weather_event.dart +++ b/lib/bloc/weather_event.dart @@ -1,10 +1,13 @@ part of 'weather_bloc.dart'; @immutable -abstract class WeatherEvent {} +abstract class WeatherEvent extends Equatable {} class GetWeather extends WeatherEvent { final String cityName; GetWeather(this.cityName); + + @override + List get props => [cityName]; } diff --git a/lib/bloc/weather_state.dart b/lib/bloc/weather_state.dart index 24425a3..5ea3f5d 100644 --- a/lib/bloc/weather_state.dart +++ b/lib/bloc/weather_state.dart @@ -1,16 +1,22 @@ part of 'weather_bloc.dart'; @immutable -abstract class WeatherState { +abstract class WeatherState extends Equatable { const WeatherState(); } class WeatherInitial extends WeatherState { const WeatherInitial(); + + @override + List get props => []; } class WeatherLoading extends WeatherState { const WeatherLoading(); + + @override + List get props => []; } class WeatherLoaded extends WeatherState { @@ -18,14 +24,7 @@ class WeatherLoaded extends WeatherState { const WeatherLoaded(this.weather); @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - - return o is WeatherLoaded && o.weather == weather; - } - - @override - int get hashCode => weather.hashCode; + List get props => [weather]; } class WeatherError extends WeatherState { @@ -33,12 +32,5 @@ class WeatherError extends WeatherState { const WeatherError(this.message); @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - - return o is WeatherError && o.message == message; - } - - @override - int get hashCode => message.hashCode; + List get props => [message]; } diff --git a/lib/cubit/weather_cubit.dart b/lib/cubit/weather_cubit.dart index 52d3d96..4f8e666 100644 --- a/lib/cubit/weather_cubit.dart +++ b/lib/cubit/weather_cubit.dart @@ -1,4 +1,5 @@ import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; import 'package:flutter_cubit_bloc_tutorial/data/model/weather.dart'; import 'package:flutter_cubit_bloc_tutorial/data/weather_repository.dart'; import 'package:meta/meta.dart'; diff --git a/lib/cubit/weather_state.dart b/lib/cubit/weather_state.dart index 111cee7..2c93a81 100644 --- a/lib/cubit/weather_state.dart +++ b/lib/cubit/weather_state.dart @@ -1,16 +1,22 @@ part of 'weather_cubit.dart'; @immutable -abstract class WeatherState { +abstract class WeatherState extends Equatable { const WeatherState(); } class WeatherInitial extends WeatherState { const WeatherInitial(); + + @override + List get props => []; } class WeatherLoading extends WeatherState { const WeatherLoading(); + + @override + List get props => []; } class WeatherLoaded extends WeatherState { @@ -18,14 +24,7 @@ class WeatherLoaded extends WeatherState { const WeatherLoaded(this.weather); @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - - return o is WeatherLoaded && o.weather == weather; - } - - @override - int get hashCode => weather.hashCode; + List get props => [weather]; } class WeatherError extends WeatherState { @@ -33,12 +32,5 @@ class WeatherError extends WeatherState { const WeatherError(this.message); @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - - return o is WeatherError && o.message == message; - } - - @override - int get hashCode => message.hashCode; + List get props => [message]; } diff --git a/lib/data/model/weather.dart b/lib/data/model/weather.dart index a930b41..b1677ef 100644 --- a/lib/data/model/weather.dart +++ b/lib/data/model/weather.dart @@ -1,4 +1,6 @@ -class Weather { +import 'package:equatable/equatable.dart'; + +class Weather extends Equatable { final String cityName; final double temperatureCelsius; @@ -8,14 +10,5 @@ class Weather { }); @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - - return o is Weather && - o.cityName == cityName && - o.temperatureCelsius == temperatureCelsius; - } - - @override - int get hashCode => cityName.hashCode ^ temperatureCelsius.hashCode; + List get props => [cityName, temperatureCelsius]; } diff --git a/pubspec.lock b/pubspec.lock index 72b558a..4c2532c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" + equatable: + dependency: "direct main" + description: + name: equatable + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c79ae31..8df2dfd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: sdk: flutter bloc: ^7.0.0 flutter_bloc: ^7.0.0 + equatable: ^2.0.2 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.