Skip to content

Commit dbe9a0d

Browse files
committed
very_good_analysis added, RiverPod version 1.0.0
1 parent c95a4d4 commit dbe9a0d

24 files changed

+222
-212
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@ lib/generated/intl/messages_bn.dart
130130
lib/generated/intl/messages_all.dart
131131

132132
*.aab
133+
.idea/dictionaries/sadmansamee.xml

analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:flutter_lints/flutter.yaml
1+
include: package:very_good_analysis/analysis_options.yaml
22

33

44
linter:

lib/app/provider/app_start_provider.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ final appStartProvider =
2020
});
2121

2222
class AppStartNotifier extends StateNotifier<AppStartState> {
23-
late final TokenRepository _tokenRepository =
24-
_reader(tokenRepositoryProvider);
25-
final AuthState _authState;
26-
final HomeState _homeState;
27-
final Reader _reader;
28-
2923
AppStartNotifier(AppStartState appStartState, this._reader, this._authState,
3024
this._homeState)
3125
: super(appStartState) {
3226
_init();
3327
}
3428

35-
void _init() async {
29+
late final TokenRepository _tokenRepository =
30+
_reader(tokenRepositoryProvider);
31+
final AuthState _authState;
32+
final HomeState _homeState;
33+
final Reader _reader;
34+
35+
Future<void> _init() async {
3636
_authState.maybeWhen(
3737
loggedIn: () {
3838
state = const AppStartState.authenticated();

lib/app/widget/app_start_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppStartPage extends ConsumerWidget {
1515

1616
return state.maybeWhen(
1717
initial: () => const LoadingWidget(),
18-
authenticated: () => HomePage(),
18+
authenticated: () => const HomePage(),
1919
unauthenticated: () => SignInPage(),
2020
internetUnAvailable: () => const ConnectionUnavailableWidget(),
2121
orElse: () => const LoadingWidget(),

lib/feature/auth/repository/auth_repository.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ class AuthRepository implements AuthRepositoryProtocol {
5454
Future<AuthState> signUp(String name, String email, String password) async {
5555
if (!Validator.isValidPassWord(password)) {
5656
return const AuthState.error(
57-
AppException.errorWithMessage('Minimum 8 characters required'));
57+
AppException.errorWithMessage('Minimum 8 characters required'),
58+
);
5859
}
5960
if (!Validator.isValidEmail(email)) {
6061
return const AuthState.error(
61-
AppException.errorWithMessage('Please enter a valid email address'));
62+
AppException.errorWithMessage('Please enter a valid email address'),
63+
);
6264
}
6365
final params = {
6466
'name': name,

lib/feature/auth/widget/sign_in_page.dart

+42-39
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,49 @@ class SignInPage extends ConsumerWidget {
1515
Widget build(BuildContext context, WidgetRef ref) {
1616
return Scaffold(
1717
body: Container(
18-
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
19-
child: Column(
20-
mainAxisAlignment: MainAxisAlignment.start,
21-
children: <Widget>[
22-
const SizedBox(height: 150),
23-
Text(context.l10n.sign_in,
24-
style: TextStyle(
25-
color: Colors.grey[800],
26-
fontWeight: FontWeight.bold,
27-
fontSize: 40)),
28-
Form(
29-
child: Column(
30-
children: [
31-
TextFormField(
32-
decoration: InputDecoration(
33-
labelText: context.l10n.email_hint),
34-
controller: _emailController,
35-
),
36-
TextFormField(
37-
decoration: InputDecoration(
38-
labelText: context.l10n.password_hint),
39-
controller: _passwordController,
40-
obscureText: true,
41-
),
42-
Column(
43-
crossAxisAlignment: CrossAxisAlignment.stretch,
44-
children: <Widget>[
45-
const SizedBox(height: 30),
46-
_widgetSignInButton(context, ref),
47-
const SizedBox(height: 30),
48-
Text(
49-
context.l10n.new_user,
50-
textAlign: TextAlign.center,
51-
),
52-
_widgetSignUpButton(context),
53-
]),
54-
],
18+
margin: const EdgeInsets.only(left: 20, right: 20),
19+
child: Column(children: <Widget>[
20+
const SizedBox(height: 150),
21+
Text(
22+
context.l10n.sign_in,
23+
style: TextStyle(
24+
color: Colors.grey[800],
25+
fontWeight: FontWeight.bold,
26+
fontSize: 40,
27+
),
28+
),
29+
Form(
30+
child: Column(
31+
children: [
32+
TextFormField(
33+
decoration: InputDecoration(
34+
labelText: context.l10n.email_hint,
35+
),
36+
controller: _emailController,
5537
),
56-
)
57-
])));
38+
TextFormField(
39+
decoration: InputDecoration(
40+
labelText: context.l10n.password_hint,
41+
),
42+
controller: _passwordController,
43+
obscureText: true,
44+
),
45+
Column(
46+
crossAxisAlignment: CrossAxisAlignment.stretch,
47+
children: <Widget>[
48+
const SizedBox(height: 30),
49+
_widgetSignInButton(context, ref),
50+
const SizedBox(height: 30),
51+
Text(
52+
context.l10n.new_user,
53+
textAlign: TextAlign.center,
54+
),
55+
_widgetSignUpButton(context),
56+
]),
57+
],
58+
),
59+
)
60+
])));
5861
}
5962

6063
Widget _widgetSignInButton(BuildContext context, WidgetRef ref) {

lib/feature/auth/widget/sign_up_page.dart

+57-51
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,69 @@ class SignUpPage extends ConsumerWidget {
1414

1515
@override
1616
Widget build(BuildContext context, WidgetRef ref) {
17-
ref.listen(authProvider, (value) {
18-
if (value is AuthState) {
19-
value.maybeWhen(loggedIn: () {
20-
context.router.popUntilRoot();
21-
}, orElse: () {
22-
{}
23-
});
17+
ref.listen(authProvider, (previous, next) {
18+
if (next is AuthState) {
19+
next.maybeWhen(
20+
loggedIn: () {
21+
context.router.popUntilRoot();
22+
},
23+
orElse: () {
24+
{}
25+
},
26+
);
2427
}
2528
});
2629

2730
return Scaffold(
2831
body: Container(
29-
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
30-
child: Column(
31-
mainAxisAlignment: MainAxisAlignment.start,
32-
children: <Widget>[
33-
const SizedBox(height: 150),
34-
Text(context.l10n.sign_up,
35-
style: TextStyle(
36-
color: Colors.grey[800],
37-
fontWeight: FontWeight.bold,
38-
fontSize: 40)),
39-
Form(
40-
child: Column(
41-
children: [
42-
TextFormField(
43-
decoration: InputDecoration(
44-
labelText: context.l10n.name_hint),
45-
controller: _nameController,
46-
),
47-
TextFormField(
48-
decoration: InputDecoration(
49-
labelText: context.l10n.email_hint),
50-
controller: _emailController,
51-
),
52-
TextFormField(
53-
decoration: InputDecoration(
54-
labelText: context.l10n.password_hint),
55-
controller: _passwordController,
56-
obscureText: true,
57-
),
58-
Column(
59-
crossAxisAlignment: CrossAxisAlignment.stretch,
60-
children: <Widget>[
61-
const SizedBox(height: 30),
62-
_widgetSignUpButton(context, ref),
63-
const SizedBox(height: 30),
64-
Text(
65-
context.l10n.already_user,
66-
textAlign: TextAlign.center,
67-
),
68-
_widgetSignInButton(context, ref),
69-
]),
70-
],
32+
margin: const EdgeInsets.only(left: 20, right: 20),
33+
child: Column(children: <Widget>[
34+
const SizedBox(height: 150),
35+
Text(
36+
context.l10n.sign_up,
37+
style: TextStyle(
38+
color: Colors.grey[800],
39+
fontWeight: FontWeight.bold,
40+
fontSize: 40),
41+
),
42+
Form(
43+
child: Column(
44+
children: [
45+
TextFormField(
46+
decoration: InputDecoration(
47+
labelText: context.l10n.name_hint,
48+
),
49+
controller: _nameController,
50+
),
51+
TextFormField(
52+
decoration: InputDecoration(
53+
labelText: context.l10n.email_hint,
54+
),
55+
controller: _emailController,
56+
),
57+
TextFormField(
58+
decoration: InputDecoration(
59+
labelText: context.l10n.password_hint,
60+
),
61+
controller: _passwordController,
62+
obscureText: true,
7163
),
72-
)
73-
])));
64+
Column(
65+
crossAxisAlignment: CrossAxisAlignment.stretch,
66+
children: <Widget>[
67+
const SizedBox(height: 30),
68+
_widgetSignUpButton(context, ref),
69+
const SizedBox(height: 30),
70+
Text(
71+
context.l10n.already_user,
72+
textAlign: TextAlign.center,
73+
),
74+
_widgetSignInButton(context, ref),
75+
]),
76+
],
77+
),
78+
)
79+
])));
7480
}
7581

7682
Widget _widgetSignInButton(BuildContext context, WidgetRef ref) {

lib/feature/home/provider/books_provider.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ final booksProvider = StateNotifierProvider<BooksProvider, BooksState>((ref) {
1111
});
1212

1313
class BooksProvider extends StateNotifier<BooksState> {
14-
final Reader _reader;
15-
final AppStartState _appStartState;
16-
17-
late final BooksRepository _repository = _reader(booksRepositoryProvider);
18-
1914
BooksProvider(this._reader, this._appStartState)
2015
: super(const BooksState.loading()) {
2116
_init();
2217
}
2318

24-
_init() async {
19+
final Reader _reader;
20+
final AppStartState _appStartState;
21+
22+
late final BooksRepository _repository = _reader(booksRepositoryProvider);
23+
24+
Future<void> _init() async {
2525
_appStartState.maybeWhen(
2626
authenticated: () {
2727
_fetchBooks();
2828
},
2929
orElse: () {});
3030
}
3131

32-
_fetchBooks() async {
32+
Future<void> _fetchBooks() async {
3333
final response = await _repository.fetchBooks();
3434
if (mounted) {
3535
state = response;

lib/feature/home/provider/home_provider.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ final homeProvider = StateNotifierProvider<HomeProvider, HomeState>((ref) {
77
});
88

99
class HomeProvider extends StateNotifier<HomeState> {
10-
HomeProvider(this._reader) : super(const HomeState.loading()) {
11-
_init();
12-
}
10+
HomeProvider(this._reader) : super(const HomeState.loading()) {}
1311
final Reader _reader;
1412
late final TokenRepository _tokenRepository =
1513
_reader(tokenRepositoryProvider);
1614

17-
_init() async {}
18-
1915
Future<void> logout() async {
2016
await _tokenRepository.remove();
2117
state = const HomeState.loggedOut();

lib/feature/home/repository/books_repository.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class BooksRepositoryProtocol {
1212
final booksRepositoryProvider = Provider((ref) => BooksRepository(ref.read));
1313

1414
class BooksRepository implements BooksRepositoryProtocol {
15-
BooksRepository(this._reader) {}
15+
BooksRepository(this._reader);
1616

1717
late final ApiProvider _api = _reader(apiProvider);
1818
final Reader _reader;
@@ -30,7 +30,8 @@ class BooksRepository implements BooksRepositoryProtocol {
3030
if (response is APISuccess) {
3131
final value = response.value;
3232
try {
33-
final List<Book> _books = booksFromJson(value);
33+
final _books = booksFromJson(value);
34+
3435
return BooksState.booksLoaded(_books);
3536
} catch (e) {
3637
return BooksState.error(AppException.errorWithMessage(e.toString()));

lib/feature/home/widget/home_page.dart

+15-12
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ class HomePage extends ConsumerWidget {
3535
Widget _widgetContent(BuildContext context, WidgetRef ref) {
3636
final state = ref.watch(booksProvider);
3737

38-
return state.when(loading: () {
39-
return _widgetShimmer(context, ref);
40-
}, booksLoaded: (books) {
41-
return ListView.builder(
42-
scrollDirection: Axis.vertical,
43-
itemCount: books.length,
44-
itemBuilder: (BuildContext context, int index) {
45-
return RowBookWidget(book: books[index]);
46-
});
47-
}, error: (AppException error) {
48-
return _widgetShimmer(context, ref);
49-
});
38+
return state.when(
39+
loading: () {
40+
return _widgetShimmer(context, ref);
41+
},
42+
booksLoaded: (books) {
43+
return ListView.builder(
44+
itemCount: books.length,
45+
itemBuilder: (BuildContext context, int index) {
46+
return RowBookWidget(book: books[index]);
47+
});
48+
},
49+
error: (AppException error) {
50+
return _widgetShimmer(context, ref);
51+
},
52+
);
5053
}
5154
}

0 commit comments

Comments
 (0)