Skip to content

Commit 43f0600

Browse files
committed
update the version of sdk with riverpod
add state notifier on new directory
1 parent 7c8a857 commit 43f0600

File tree

6 files changed

+127
-41
lines changed

6 files changed

+127
-41
lines changed

lib/main.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import 'package:exploring_riverpod/page/counterPage.dart';
1+
import 'package:exploring_riverpod/page/counterPage-notifer.dart';
2+
// import 'package:exploring_riverpod/page/counterPage.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter_riverpod/flutter_riverpod.dart';
45

@@ -16,7 +17,8 @@ class MyApp extends StatelessWidget {
1617
backgroundColor: Colors.lightBlue.withBlue(3)),
1718
),
1819
debugShowCheckedModeBanner: false,
19-
home: CounterPage(),
20+
// home: CounterPage(), // for ChangeNotifier
21+
home: CounterNotiferPage(), // for state notifer
2022
);
2123
}
2224
}

lib/page/counterPage-notifer.dart

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'package:exploring_riverpod/riverpod_counter.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_riverpod/flutter_riverpod.dart';
4+
5+
class CounterNotiferPage extends ConsumerWidget {
6+
@override
7+
Widget build(BuildContext context, WidgetRef ref) {
8+
final mq = MediaQuery.of(context).size;
9+
var counter = ref.watch(counterNotifierProvider);
10+
final appName = ref.watch(appNameRiverpod);
11+
return SafeArea(
12+
child: Scaffold(
13+
appBar: appBar(appName, context),
14+
floatingActionButton: rowfloatingActionButton(ref, mq),
15+
body: Column(
16+
mainAxisAlignment: MainAxisAlignment.center,
17+
crossAxisAlignment: CrossAxisAlignment.center,
18+
children: [
19+
Center(
20+
child: Text(
21+
"Value : " + counter.toString(),
22+
style: Theme.of(context)
23+
.textTheme
24+
.headline6!
25+
.copyWith(color: Colors.white),
26+
),
27+
),
28+
SizedBox(
29+
height: mq.height * 0.02,
30+
),
31+
Text(
32+
"Hope You'll like this! \nKeep Learning and Stay Safe",
33+
style: Theme.of(context)
34+
.textTheme
35+
.caption!
36+
.copyWith(color: Colors.white),
37+
),
38+
],
39+
),
40+
),
41+
);
42+
}
43+
44+
Widget rowfloatingActionButton(WidgetRef ref, Size mq) {
45+
return Row(
46+
mainAxisAlignment: MainAxisAlignment.end,
47+
children: [
48+
FloatingActionButton(
49+
onPressed: () {
50+
ref.read(counterNotifierProvider.notifier).add();
51+
},
52+
child: Icon(Icons.add),
53+
),
54+
SizedBox(
55+
width: mq.width * 0.02,
56+
),
57+
FloatingActionButton(
58+
onPressed: () {
59+
ref.read(counterNotifierProvider.notifier).subtract();
60+
},
61+
child: Icon(Icons.remove),
62+
),
63+
],
64+
);
65+
}
66+
67+
AppBar appBar(String appName, BuildContext context) {
68+
return AppBar(
69+
backgroundColor: Colors.transparent,
70+
elevation: 0,
71+
centerTitle: true,
72+
title: Text(
73+
'$appName',
74+
style: Theme.of(context)
75+
.textTheme
76+
.headline5!
77+
.copyWith(color: Colors.white),
78+
),
79+
);
80+
}
81+
}

lib/page/counterPage.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CounterPage extends ConsumerWidget {
2525
"Value : " + applyCount.value.toString(),
2626
style: Theme.of(context)
2727
.textTheme
28-
.headline6
28+
.headline6!
2929
.copyWith(color: Colors.white),
3030
),
3131
),
@@ -36,7 +36,7 @@ class CounterPage extends ConsumerWidget {
3636
"Hope You'll like this! \nKeep Learning and Stay Safe",
3737
style: Theme.of(context)
3838
.textTheme
39-
.caption
39+
.caption!
4040
.copyWith(color: Colors.white),
4141
),
4242
],
@@ -53,7 +53,7 @@ class CounterPage extends ConsumerWidget {
5353
title: Text(
5454
'$appName',
5555
style:
56-
Theme.of(context).textTheme.headline5.copyWith(color: Colors.white),
56+
Theme.of(context).textTheme.headline5!.copyWith(color: Colors.white),
5757
),
5858
);
5959
}

lib/riverpod_counter.dart

+10
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ class CounterRiverpod extends ChangeNotifier {
1818
notifyListeners();
1919
}
2020
}
21+
22+
final counterNotifierProvider =
23+
StateNotifierProvider<CounterNotifer, int>((_) => CounterNotifer());
24+
25+
class CounterNotifer extends StateNotifier<int> {
26+
CounterNotifer() : super(0);
27+
28+
void add() => state = state + 1;
29+
void subtract() => state = state - 1;
30+
}

pubspec.lock

+26-33
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.8.2"
10+
version: "2.9.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,42 +21,35 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.2.0"
25-
charcode:
26-
dependency: transitive
27-
description:
28-
name: charcode
29-
url: "https://pub.dartlang.org"
30-
source: hosted
31-
version: "1.3.1"
24+
version: "1.2.1"
3225
clock:
3326
dependency: transitive
3427
description:
3528
name: clock
3629
url: "https://pub.dartlang.org"
3730
source: hosted
38-
version: "1.1.0"
31+
version: "1.1.1"
3932
collection:
4033
dependency: transitive
4134
description:
4235
name: collection
4336
url: "https://pub.dartlang.org"
4437
source: hosted
45-
version: "1.15.0"
38+
version: "1.16.0"
4639
cupertino_icons:
4740
dependency: "direct main"
4841
description:
4942
name: cupertino_icons
5043
url: "https://pub.dartlang.org"
5144
source: hosted
52-
version: "1.0.3"
45+
version: "1.0.5"
5346
fake_async:
5447
dependency: transitive
5548
description:
5649
name: fake_async
5750
url: "https://pub.dartlang.org"
5851
source: hosted
59-
version: "1.2.0"
52+
version: "1.3.1"
6053
flutter:
6154
dependency: "direct main"
6255
description: flutter
@@ -68,7 +61,7 @@ packages:
6861
name: flutter_riverpod
6962
url: "https://pub.dartlang.org"
7063
source: hosted
71-
version: "1.0.3"
64+
version: "2.0.2"
7265
flutter_test:
7366
dependency: "direct dev"
7467
description: flutter
@@ -80,28 +73,35 @@ packages:
8073
name: matcher
8174
url: "https://pub.dartlang.org"
8275
source: hosted
83-
version: "0.12.11"
76+
version: "0.12.12"
77+
material_color_utilities:
78+
dependency: transitive
79+
description:
80+
name: material_color_utilities
81+
url: "https://pub.dartlang.org"
82+
source: hosted
83+
version: "0.1.5"
8484
meta:
8585
dependency: transitive
8686
description:
8787
name: meta
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "1.7.0"
90+
version: "1.8.0"
9191
path:
9292
dependency: transitive
9393
description:
9494
name: path
9595
url: "https://pub.dartlang.org"
9696
source: hosted
97-
version: "1.8.0"
97+
version: "1.8.2"
9898
riverpod:
9999
dependency: transitive
100100
description:
101101
name: riverpod
102102
url: "https://pub.dartlang.org"
103103
source: hosted
104-
version: "1.0.3"
104+
version: "2.0.2"
105105
sky_engine:
106106
dependency: transitive
107107
description: flutter
@@ -113,7 +113,7 @@ packages:
113113
name: source_span
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "1.8.1"
116+
version: "1.9.0"
117117
stack_trace:
118118
dependency: transitive
119119
description:
@@ -127,7 +127,7 @@ packages:
127127
name: state_notifier
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "0.7.0"
130+
version: "0.7.2+1"
131131
stream_channel:
132132
dependency: transitive
133133
description:
@@ -141,35 +141,28 @@ packages:
141141
name: string_scanner
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "1.1.0"
144+
version: "1.1.1"
145145
term_glyph:
146146
dependency: transitive
147147
description:
148148
name: term_glyph
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "1.2.0"
151+
version: "1.2.1"
152152
test_api:
153153
dependency: transitive
154154
description:
155155
name: test_api
156156
url: "https://pub.dartlang.org"
157157
source: hosted
158-
version: "0.4.3"
159-
typed_data:
160-
dependency: transitive
161-
description:
162-
name: typed_data
163-
url: "https://pub.dartlang.org"
164-
source: hosted
165-
version: "1.3.0"
158+
version: "0.4.12"
166159
vector_math:
167160
dependency: transitive
168161
description:
169162
name: vector_math
170163
url: "https://pub.dartlang.org"
171164
source: hosted
172-
version: "2.1.1"
165+
version: "2.1.2"
173166
sdks:
174-
dart: ">=2.14.0 <3.0.0"
175-
flutter: ">=1.17.0"
167+
dart: ">=2.18.0 <3.0.0"
168+
flutter: ">=3.0.0"

pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
1818
version: 1.0.0+1
1919

2020
environment:
21-
sdk: ">=2.7.0 <3.0.0"
21+
sdk: ">=2.18.0 <3.0.0"
2222

2323
dependencies:
24-
cupertino_icons: ^1.0.2
24+
cupertino_icons: ^1.0.5
2525
flutter:
2626
sdk: flutter
27-
flutter_riverpod: ^1.0.3
27+
flutter_riverpod: ^2.0.2
2828

2929
dev_dependencies:
3030
flutter_test:

0 commit comments

Comments
 (0)