Skip to content

Commit 03afcd3

Browse files
committed
Update dependencies
1 parent a2af421 commit 03afcd3

File tree

14 files changed

+540
-829
lines changed

14 files changed

+540
-829
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]}

.idea/libraries/Dart_Packages.xml

Lines changed: 133 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Flutter_Plugins.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 22 additions & 405 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
# This is a generated file; do not edit or check into version control.
3+
export "FLUTTER_ROOT=C:\flutter\flutter"
4+
export "FLUTTER_APPLICATION_PATH=E:\Admin\Documents\Android\search-book"
5+
export "FLUTTER_TARGET=lib\main.dart"
6+
export "FLUTTER_BUILD_DIR=build"
7+
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
8+
export "FLUTTER_FRAMEWORK_DIR=C:\flutter\flutter\bin\cache\artifacts\engine\ios"
9+
export "FLUTTER_BUILD_NAME=1.0.0"
10+
export "FLUTTER_BUILD_NUMBER=1"

lib/generated/i18n.dart

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import 'package:flutter/material.dart';
77
// ignore_for_file: camel_case_types
88
// ignore_for_file: prefer_single_quotes
99

10-
//This file is automatically generated. DO NOT EDIT, all your changes would be lost.
10+
// This file is automatically generated. DO NOT EDIT, all your changes would be lost.
1111
class S implements WidgetsLocalizations {
1212
const S();
1313

14+
static S current;
15+
1416
static const GeneratedLocalizationsDelegate delegate =
1517
GeneratedLocalizationsDelegate();
1618

@@ -34,24 +36,49 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
3436
];
3537
}
3638

37-
LocaleListResolutionCallback listResolution({Locale fallback}) {
39+
LocaleListResolutionCallback listResolution({Locale fallback, bool withCountry = true}) {
3840
return (List<Locale> locales, Iterable<Locale> supported) {
3941
if (locales == null || locales.isEmpty) {
4042
return fallback ?? supported.first;
4143
} else {
42-
return _resolve(locales.first, fallback, supported);
44+
return _resolve(locales.first, fallback, supported, withCountry);
4345
}
4446
};
4547
}
4648

47-
LocaleResolutionCallback resolution({Locale fallback}) {
49+
LocaleResolutionCallback resolution({Locale fallback, bool withCountry = true}) {
4850
return (Locale locale, Iterable<Locale> supported) {
49-
return _resolve(locale, fallback, supported);
51+
return _resolve(locale, fallback, supported, withCountry);
5052
};
5153
}
5254

53-
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported) {
54-
if (locale == null || !isSupported(locale)) {
55+
@override
56+
Future<S> load(Locale locale) {
57+
final String lang = getLang(locale);
58+
if (lang != null) {
59+
switch (lang) {
60+
case "en":
61+
S.current = const $en();
62+
return SynchronousFuture<S>(S.current);
63+
default:
64+
// NO-OP.
65+
}
66+
}
67+
S.current = const S();
68+
return SynchronousFuture<S>(S.current);
69+
}
70+
71+
@override
72+
bool isSupported(Locale locale) => _isSupported(locale, true);
73+
74+
@override
75+
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
76+
77+
///
78+
/// Internal method to resolve a locale from a list of locales.
79+
///
80+
Locale _resolve(Locale locale, Locale fallback, Iterable<Locale> supported, bool withCountry) {
81+
if (locale == null || !_isSupported(locale, withCountry)) {
5582
return fallback ?? supported.first;
5683
}
5784

@@ -66,26 +93,30 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
6693
}
6794
}
6895

69-
@override
70-
Future<S> load(Locale locale) {
71-
final String lang = getLang(locale);
72-
if (lang != null) {
73-
switch (lang) {
74-
case "en":
75-
return SynchronousFuture<S>(const $en());
76-
default:
77-
// NO-OP.
96+
///
97+
/// Returns true if the specified locale is supported, false otherwise.
98+
///
99+
bool _isSupported(Locale locale, bool withCountry) {
100+
if (locale != null) {
101+
for (Locale supportedLocale in supportedLocales) {
102+
// Language must always match both locales.
103+
if (supportedLocale.languageCode != locale.languageCode) {
104+
continue;
105+
}
106+
107+
// If country code matches, return this locale.
108+
if (supportedLocale.countryCode == locale.countryCode) {
109+
return true;
110+
}
111+
112+
// If no country requirement is requested, check if this locale has no country.
113+
if (true != withCountry && (supportedLocale.countryCode == null || supportedLocale.countryCode.isEmpty)) {
114+
return true;
115+
}
78116
}
79117
}
80-
return SynchronousFuture<S>(const S());
118+
return false;
81119
}
82-
83-
@override
84-
bool isSupported(Locale locale) =>
85-
locale != null && supportedLocales.contains(locale);
86-
87-
@override
88-
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
89120
}
90121

91122
String getLang(Locale l) => l == null

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class CustomBuiltValueToStringHelper implements BuiltValueToStringHelper {
4343
}
4444

4545
void main() async {
46+
WidgetsFlutterBinding.ensureInitialized();
47+
4648
newBuiltValueToStringHelper =
4749
(className) => CustomBuiltValueToStringHelper(className);
4850

lib/pages/detail_page/detail_bloc.dart

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,26 @@ import 'dart:async';
22

33
import 'package:built_collection/built_collection.dart';
44
import 'package:disposebag/disposebag.dart';
5+
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
6+
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
7+
import 'package:rxdart/rxdart.dart';
58
import 'package:search_book/domain/book.dart';
69
import 'package:search_book/domain/book_repo.dart';
710
import 'package:search_book/pages/detail_page/detail_state.dart';
811
import 'package:search_book/shared_pref.dart';
9-
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
10-
import 'package:rxdart/rxdart.dart';
11-
import 'package:distinct_value_connectable_observable/distinct_value_connectable_observable.dart';
1212

1313
// ignore_for_file: close_sinks
1414

1515
class DetailBloc implements BaseBloc {
16-
///
17-
///
18-
///
19-
final ValueObservable<BookDetailState> bookDetail$;
16+
/// Outputs
17+
final ValueStream<BookDetailState> bookDetail$;
2018
final Stream<Object> error$;
2119

22-
///
23-
///
24-
///
20+
/// Inputs
2521
final Future<void> Function() refresh;
2622
final void Function() toggleFavorited;
2723

28-
///
2924
/// Clean up resource
30-
///
3125
final void Function() _dispose;
3226

3327
DetailBloc._(
@@ -47,6 +41,7 @@ class DetailBloc implements BaseBloc {
4741
assert(sharedPref != null);
4842
assert(initial != null);
4943

44+
/// Controllers
5045
final refreshController = PublishSubject<Completer>();
5146
final errorController = PublishSubject<Object>();
5247
final toggleController = PublishSubject<void>();
@@ -63,7 +58,7 @@ class DetailBloc implements BaseBloc {
6358
},
6459
).startWith(initial);
6560

66-
final state$ = Observable.combineLatest2(
61+
final state$ = Rx.combineLatest2(
6762
book$,
6863
sharedPref.favoritedIds$,
6964
(Book book, BuiltSet<String> ids) {
@@ -72,25 +67,18 @@ class DetailBloc implements BaseBloc {
7267
ids.contains(book.id),
7368
);
7469
},
75-
);
76-
77-
final bookDetail$ = publishValueSeededDistinct(
78-
state$,
79-
seedValue: BookDetailState.fromDomain(initial),
80-
);
81-
82-
///
83-
///
84-
///
70+
).publishValueSeededDistinct(
71+
seedValue: BookDetailState.fromDomain(initial));
8572

73+
/// DisposeBag
8674
final bag = DisposeBag(
8775
[
8876
toggleController
8977
.throttleTime(const Duration(milliseconds: 600))
9078
.listen((_) => sharedPref.toggleFavorite(initial.id)),
91-
bookDetail$.listen((book) => print('[DETAIL] book=$book')),
79+
state$.listen((book) => print('[DETAIL] book=$book')),
9280
//
93-
bookDetail$.connect(),
81+
state$.connect(),
9482
//
9583
refreshController,
9684
errorController,
@@ -101,7 +89,7 @@ class DetailBloc implements BaseBloc {
10189
print('[DETAIL] new id=${initial.id}');
10290

10391
return DetailBloc._(
104-
bookDetail$,
92+
state$,
10593
errorController,
10694
() {
10795
final completer = Completer<void>();

lib/pages/fav_page/fav_books_bloc.dart

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import 'dart:async';
22

33
import 'package:built_collection/built_collection.dart';
44
import 'package:disposebag/disposebag.dart';
5+
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
6+
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
7+
import 'package:rxdart/rxdart.dart';
58
import 'package:search_book/domain/book_repo.dart';
69
import 'package:search_book/domain/cache_policy.dart';
710
import 'package:search_book/pages/fav_page/fav_books_state.dart';
811
import 'package:search_book/shared_pref.dart';
9-
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
10-
import 'package:distinct_value_connectable_observable/distinct_value_connectable_observable.dart';
11-
import 'package:rxdart/rxdart.dart';
1212
import 'package:tuple/tuple.dart';
1313

14+
// ignore_for_file: close_sinks
15+
1416
class FavBooksInteractor {
1517
final BookRepo _bookRepo;
16-
final ValueObservable<BuiltSet<String>> favoritedIds$;
18+
final ValueStream<BuiltSet<String>> favoritedIds$;
1719
final void Function(String) toggleFavorite;
1820

1921
FavBooksInteractor(this._bookRepo, SharedPref _sharedPref)
@@ -27,14 +29,14 @@ class FavBooksInteractor {
2729
bool forceUpdate = false,
2830
Completer<void> completer,
2931
]) {
30-
return Observable.fromIterable(ids)
32+
return Stream.fromIterable(ids)
3133
.flatMap((id) {
3234
final stream = _bookRepo.getBookBy(
3335
id: id,
3436
cachePolicy:
3537
forceUpdate ? CachePolicy.networkOnly : CachePolicy.localFirst,
3638
);
37-
return Observable(stream)
39+
return stream
3840
.map<FavBookPartialChange>((book) => LoadedFavBookChange(book))
3941
.onErrorReturnWith((e) => ErrorFavBookChange(e));
4042
})
@@ -43,23 +45,15 @@ class FavBooksInteractor {
4345
}
4446
}
4547

46-
// ignore_for_file: close_sinks
47-
4848
class FavBooksBloc implements BaseBloc {
49-
///
50-
///
51-
///
49+
/// Inputs
5250
final void Function(String) removeFavorite;
5351
final Future<void> Function() refresh;
5452

55-
///
56-
///
57-
///
58-
final ValueObservable<FavBooksState> state$;
53+
/// Outputs
54+
final ValueStream<FavBooksState> state$;
5955

60-
///
61-
///
62-
///
56+
/// Clean up resources
6357
final void Function() _dispose;
6458

6559
FavBooksBloc._(
@@ -75,32 +69,29 @@ class FavBooksBloc implements BaseBloc {
7569
factory FavBooksBloc(final FavBooksInteractor interactor) {
7670
assert(interactor != null, 'interactor cannot be null');
7771

72+
/// Controllers
7873
final removeFavoriteController = PublishSubject<String>();
7974
final refreshController = PublishSubject<Completer<void>>();
8075

81-
final state$ = publishValueSeededDistinct(
82-
Observable.merge(
83-
[
84-
interactor.favoritedIds$.switchMap(interactor.partialChanges),
85-
refreshController
86-
.withLatestFrom(
87-
interactor.favoritedIds$,
88-
(Completer<void> completer, BuiltSet<String> ids) =>
89-
Tuple2(completer, ids),
90-
)
91-
.exhaustMap((tuple2) =>
92-
interactor.partialChanges(tuple2.item2, true, tuple2.item1)),
93-
],
94-
)
95-
.doOnData((change) => print('[FAV_BOOKS] change=$change'))
96-
.scan(_reducer, FavBooksState.initial()),
97-
seedValue: FavBooksState.initial(),
98-
);
99-
100-
///
101-
///
102-
///
76+
/// State stream
77+
final state$ = Rx.merge(
78+
[
79+
interactor.favoritedIds$.switchMap(interactor.partialChanges),
80+
refreshController
81+
.withLatestFrom(
82+
interactor.favoritedIds$,
83+
(Completer<void> completer, BuiltSet<String> ids) =>
84+
Tuple2(completer, ids),
85+
)
86+
.exhaustMap((tuple2) =>
87+
interactor.partialChanges(tuple2.item2, true, tuple2.item1)),
88+
],
89+
)
90+
.doOnData((change) => print('[FAV_BOOKS] change=$change'))
91+
.scan(_reducer, FavBooksState.initial())
92+
.publishValueSeededDistinct(seedValue: FavBooksState.initial());
10393

94+
/// DisposeBag
10495
final bag = DisposeBag(
10596
[
10697
refreshController,

0 commit comments

Comments
 (0)