Skip to content

Commit 965d2e7

Browse files
authored
lints & deps (#12)
1 parent 4c1d062 commit 965d2e7

14 files changed

+203
-116
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Petrus Nguyễn Thái Học <[email protected]>

analysis_options.yaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
include: package:pedantic/analysis_options.1.11.0.yaml
1+
include: package:flutter_lints/flutter.yaml
22
analyzer:
33
strong-mode:
44
implicit-casts: false
55
implicit-dynamic: false
66
linter:
77
rules:
8-
- prefer_final_locals
98
- public_member_api_docs
10-
- prefer_relative_imports
9+
- prefer_final_locals
10+
- prefer_relative_imports
11+
# https://github.com/dart-lang/lints#migrating-from-packagepedantic
12+
- always_declare_return_types
13+
- prefer_single_quotes
14+
- unawaited_futures
15+
- unsafe_html

example/analysis_options.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
include: package:pedantic/analysis_options.1.11.0.yaml
1+
include: package:flutter_lints/flutter.yaml
22
linter:
33
rules:
44
- prefer_final_locals
5-
- prefer_relative_imports
5+
- prefer_relative_imports
6+
# https://github.com/dart-lang/lints#migrating-from-packagepedantic
7+
- always_declare_return_types
8+
- prefer_single_quotes
9+
- unawaited_futures
10+
- unsafe_html

example/lib/bloc_with_deps.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// ignore_for_file: avoid_print
2+
13
import 'dart:async';
24

3-
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
45
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
56
import 'package:rxdart_ext/rxdart_ext.dart';
67

@@ -24,7 +25,7 @@ class Dependencies {
2425
class Bloc1 extends DisposeCallbackBaseBloc {
2526
final VoidAction load;
2627

27-
final DistinctValueStream<String?> string$;
28+
final StateStream<String?> string$;
2829

2930
Bloc1._({
3031
required void Function() dispose,
@@ -39,7 +40,7 @@ class Bloc1 extends DisposeCallbackBaseBloc {
3940
final string$ = loadS.stream
4041
.switchMap((value) => Rx.fromCallable(dependencies.loadSomething))
4142
.cast<String?>()
42-
.publishValueDistinct(null);
43+
.publishState(null);
4344
final connection = string$.connect();
4445

4546
return Bloc1._(

example/lib/counter_bloc.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// ignore_for_file: avoid_print
2+
13
import 'dart:async';
24

3-
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
45
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
56
import 'package:rxdart_ext/rxdart_ext.dart';
67

@@ -9,7 +10,7 @@ class CounterBloc extends DisposeCallbackBaseBloc {
910
final VoidAction increment;
1011

1112
/// Outputs
12-
final DistinctValueStream<int> state;
13+
final StateStream<int> state;
1314

1415
CounterBloc._({
1516
required void Function() dispose,
@@ -23,7 +24,7 @@ class CounterBloc extends DisposeCallbackBaseBloc {
2324

2425
final state = incrementController.stream
2526
.scan<int>((acc, _, __) => acc + 1, 0)
26-
.publishValueDistinct(0);
27+
.publishState(0);
2728
final connection = state.connect();
2829

2930
return CounterBloc._(

example/lib/main.dart

+43-32
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart';
34
import 'package:flutter_provider/flutter_provider.dart';
45

56
import 'bloc_with_deps.dart';
67
import 'counter_bloc.dart';
78

8-
void main() => runApp(MyApp());
9+
void main() {
10+
RxStreamBuilder.checkStateStreamEnabled = !kReleaseMode;
11+
runApp(const MyApp());
12+
}
913

1014
class MyApp extends StatelessWidget {
15+
const MyApp({Key? key}) : super(key: key);
16+
1117
@override
1218
Widget build(BuildContext context) {
1319
return Provider<Dependencies>.factory(
@@ -16,46 +22,48 @@ class MyApp extends StatelessWidget {
1622
child: MaterialApp(
1723
title: 'Flutter bloc pattern',
1824
theme: ThemeData.dark(),
19-
home: StartPage(),
25+
home: const StartPage(),
2026
),
2127
);
2228
}
2329
}
2430

2531
class StartPage extends StatelessWidget {
32+
const StartPage({Key? key}) : super(key: key);
33+
2634
@override
2735
Widget build(BuildContext context) {
28-
return Container(
29-
child: Center(
30-
child: TextButton(
31-
onPressed: () => Navigator.of(context).push(
32-
MaterialPageRoute(
33-
builder: (context) {
34-
return BlocProvider<CounterBloc>(
35-
initBloc: (_) => CounterBloc(),
36-
child: BlocProviders(
37-
blocProviders: [
38-
BlocProvider<Bloc1>(
39-
initBloc: (context) => Bloc1(context.get()),
40-
),
41-
BlocProvider<Bloc2>(
42-
initBloc: (context) => Bloc2(context.bloc()),
43-
),
44-
],
45-
child: MyHomePage(),
46-
),
47-
);
48-
},
49-
),
36+
return Center(
37+
child: TextButton(
38+
onPressed: () => Navigator.of(context).push(
39+
MaterialPageRoute(
40+
builder: (context) {
41+
return BlocProvider<CounterBloc>(
42+
initBloc: (_) => CounterBloc(),
43+
child: BlocProviders(
44+
blocProviders: [
45+
BlocProvider<Bloc1>(
46+
initBloc: (context) => Bloc1(context.get()),
47+
),
48+
BlocProvider<Bloc2>(
49+
initBloc: (context) => Bloc2(context.bloc()),
50+
),
51+
],
52+
child: const MyHomePage(),
53+
),
54+
);
55+
},
5056
),
51-
child: Text('GO TO HOME'),
5257
),
58+
child: const Text('GO TO HOME'),
5359
),
5460
);
5561
}
5662
}
5763

5864
class MyHomePage extends StatefulWidget {
65+
const MyHomePage({Key? key}) : super(key: key);
66+
5967
@override
6068
_MyHomePageState createState() => _MyHomePageState();
6169
}
@@ -65,21 +73,22 @@ class _MyHomePageState extends State<MyHomePage> {
6573
Widget build(BuildContext context) {
6674
return Scaffold(
6775
appBar: AppBar(
68-
title: Text('Home page'),
76+
title: const Text('Home page'),
6977
),
7078
body: Center(
7179
child: Column(
7280
mainAxisAlignment: MainAxisAlignment.center,
7381
children: <Widget>[
74-
Text('You have pushed the button this many times:'),
82+
const Text('You have pushed the button this many times:'),
83+
const SizedBox(height: 8),
84+
const TextCounter1(),
85+
const TextCounter2(),
7586
const SizedBox(height: 8),
76-
TextCounter1(),
77-
TextCounter2(),
87+
const TextBloc1(),
7888
const SizedBox(height: 8),
79-
TextBloc1(),
8089
ElevatedButton(
8190
onPressed: () => context.bloc<Bloc2>(),
82-
child: Text('Access Bloc 2'),
91+
child: const Text('Access Bloc 2'),
8392
)
8493
],
8594
),
@@ -137,12 +146,14 @@ class IncrementButton extends StatelessWidget {
137146
return FloatingActionButton(
138147
onPressed: bloc.increment,
139148
tooltip: 'Increment',
140-
child: Icon(Icons.add),
149+
child: const Icon(Icons.add),
141150
);
142151
}
143152
}
144153

145154
class TextBloc1 extends StatelessWidget {
155+
const TextBloc1({Key? key}) : super(key: key);
156+
146157
@override
147158
Widget build(BuildContext context) {
148159
final bloc = context.bloc<Bloc1>();

example/pubspec.lock

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.6.1"
10+
version: "2.8.1"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -28,7 +28,7 @@ packages:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.2.0"
31+
version: "1.3.1"
3232
clock:
3333
dependency: transitive
3434
description:
@@ -50,13 +50,6 @@ packages:
5050
url: "https://pub.dartlang.org"
5151
source: hosted
5252
version: "1.0.3"
53-
distinct_value_connectable_stream:
54-
dependency: "direct main"
55-
description:
56-
name: distinct_value_connectable_stream
57-
url: "https://pub.dartlang.org"
58-
source: hosted
59-
version: "1.3.0"
6053
fake_async:
6154
dependency: transitive
6255
description:
@@ -75,7 +68,14 @@ packages:
7568
path: ".."
7669
relative: true
7770
source: path
78-
version: "2.1.1"
71+
version: "2.2.0"
72+
flutter_lints:
73+
dependency: "direct dev"
74+
description:
75+
name: flutter_lints
76+
url: "https://pub.dartlang.org"
77+
source: hosted
78+
version: "1.0.4"
7979
flutter_provider:
8080
dependency: transitive
8181
description:
@@ -88,6 +88,13 @@ packages:
8888
description: flutter
8989
source: sdk
9090
version: "0.0.0"
91+
lints:
92+
dependency: transitive
93+
description:
94+
name: lints
95+
url: "https://pub.dartlang.org"
96+
source: hosted
97+
version: "1.0.1"
9198
matcher:
9299
dependency: transitive
93100
description:
@@ -101,35 +108,28 @@ packages:
101108
name: meta
102109
url: "https://pub.dartlang.org"
103110
source: hosted
104-
version: "1.3.0"
111+
version: "1.7.0"
105112
path:
106113
dependency: transitive
107114
description:
108115
name: path
109116
url: "https://pub.dartlang.org"
110117
source: hosted
111118
version: "1.8.0"
112-
pedantic:
113-
dependency: "direct dev"
114-
description:
115-
name: pedantic
116-
url: "https://pub.dartlang.org"
117-
source: hosted
118-
version: "1.11.0"
119119
rxdart:
120120
dependency: transitive
121121
description:
122122
name: rxdart
123123
url: "https://pub.dartlang.org"
124124
source: hosted
125-
version: "0.27.0"
125+
version: "0.27.2"
126126
rxdart_ext:
127127
dependency: "direct main"
128128
description:
129129
name: rxdart_ext
130130
url: "https://pub.dartlang.org"
131131
source: hosted
132-
version: "0.1.0"
132+
version: "0.1.2"
133133
sky_engine:
134134
dependency: transitive
135135
description: flutter
@@ -176,7 +176,7 @@ packages:
176176
name: test_api
177177
url: "https://pub.dartlang.org"
178178
source: hosted
179-
version: "0.3.0"
179+
version: "0.4.2"
180180
typed_data:
181181
dependency: transitive
182182
description:

example/pubspec.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ environment:
77
sdk: ">=2.12.0-0 <3.0.0"
88

99
dependencies:
10-
distinct_value_connectable_stream: ^1.3.0
11-
rxdart_ext: ^0.1.0
10+
rxdart_ext: ^0.1.2
1211
flutter_bloc_pattern:
1312
flutter:
1413
sdk: flutter
1514
cupertino_icons: ^1.0.3
1615

1716
dev_dependencies:
18-
pedantic: ^1.11.0
17+
flutter_lints: ^1.0.4
1918
flutter_test:
2019
sdk: flutter
2120

lib/src/error.dart

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:rxdart_ext/rxdart_ext.dart';
2+
13
import 'rx_stream_builder.dart';
24

35
/// If the BlocProvider.of method fails, this error will be thrown.
@@ -33,7 +35,7 @@ class UnhandledStreamError extends Error {
3335
/// Error emitted from [Stream].
3436
final Object error;
3537

36-
/// Create a [UnhandledStreamError] from [error].
38+
/// Create an [UnhandledStreamError] from [error].
3739
UnhandledStreamError(this.error);
3840

3941
@override
@@ -53,3 +55,20 @@ https://github.com/hoc081098/flutter_bloc_pattern/issues/new
5355
''';
5456
}
5557
}
58+
59+
/// Invalid state error caused by a [StateStream].
60+
class InvalidStateStreamError<T> extends Error {
61+
/// The [StateStream] causes this error.
62+
final StateStream<T> stream;
63+
64+
/// The value causes this error.
65+
final T value;
66+
67+
/// Create an [InvalidStateStreamError].
68+
InvalidStateStreamError(this.stream, this.value);
69+
70+
@override
71+
String toString() =>
72+
'Invalid state caused by ${stream.runtimeType} ~ ${identityHashCode(stream)} ~ $stream. '
73+
'Two consecutive values are equal, the value is $value';
74+
}

0 commit comments

Comments
 (0)