Skip to content

Commit 3613efd

Browse files
Updated deprecated widgets with new one (#682)
1 parent 2f6767f commit 3613efd

File tree

3 files changed

+77
-85
lines changed

3 files changed

+77
-85
lines changed

platform_channels/lib/src/method_channel_demo.dart

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,70 +22,66 @@ class _MethodChannelDemoState extends State<MethodChannelDemo> {
2222
appBar: AppBar(
2323
title: const Text('MethodChannel Demo'),
2424
),
25-
body: Builder(
26-
builder: (context) {
27-
return Column(
28-
mainAxisAlignment: MainAxisAlignment.center,
25+
body: Column(
26+
mainAxisAlignment: MainAxisAlignment.center,
27+
children: [
28+
Text(
29+
'Value of count is $count',
30+
style: Theme.of(context).textTheme.headline5,
31+
),
32+
SizedBox(
33+
height: 16,
34+
),
35+
Row(
36+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
2937
children: [
30-
Text(
31-
'Value of count is $count',
32-
style: Theme.of(context).textTheme.headline5,
38+
// Whenever users press the ElevatedButton, it invokes
39+
// Counter.increment method to increment the value of count.
40+
ElevatedButton.icon(
41+
onPressed: () async {
42+
try {
43+
final value = await Counter.increment(counterValue: count);
44+
setState(() => count = value);
45+
} catch (error) {
46+
showErrorMessage(
47+
context,
48+
error.message as String,
49+
);
50+
}
51+
},
52+
icon: Icon(Icons.add),
53+
label: Text('Increment'),
3354
),
34-
SizedBox(
35-
height: 16,
36-
),
37-
Row(
38-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
39-
children: [
40-
// Whenever users press the ElevatedButton, it invokes
41-
// Counter.increment method to increment the value of count.
42-
ElevatedButton.icon(
43-
onPressed: () async {
44-
try {
45-
final value =
46-
await Counter.increment(counterValue: count);
47-
setState(() => count = value);
48-
} catch (error) {
49-
showErrorMessage(
50-
context,
51-
error.message as String,
52-
);
53-
}
54-
},
55-
icon: Icon(Icons.add),
56-
label: Text('Increment'),
57-
),
5855

59-
// Whenever users press the ElevatedButton, it invokes
60-
// Counter.decrement method to decrement the value of count.
61-
ElevatedButton.icon(
62-
onPressed: () async {
63-
try {
64-
final value =
65-
await Counter.decrement(counterValue: count);
66-
setState(() => count = value);
67-
} catch (error) {
68-
showErrorMessage(
69-
context,
70-
error.message as String,
71-
);
72-
}
73-
},
74-
icon: Icon(Icons.remove),
75-
label: Text('Decrement'),
76-
)
77-
],
56+
// Whenever users press the ElevatedButton, it invokes
57+
// Counter.decrement method to decrement the value of count.
58+
ElevatedButton.icon(
59+
onPressed: () async {
60+
try {
61+
final value = await Counter.decrement(counterValue: count);
62+
setState(() => count = value);
63+
} catch (error) {
64+
showErrorMessage(
65+
context,
66+
error.message as String,
67+
);
68+
}
69+
},
70+
icon: Icon(Icons.remove),
71+
label: Text('Decrement'),
7872
)
7973
],
80-
);
81-
},
74+
)
75+
],
8276
),
8377
);
8478
}
8579

8680
void showErrorMessage(BuildContext context, String errorMessage) {
87-
Scaffold.of(context).showSnackBar(SnackBar(
88-
content: Text(errorMessage),
89-
));
81+
ScaffoldMessenger.of(context).showSnackBar(
82+
SnackBar(
83+
content: Text(errorMessage),
84+
),
85+
);
9086
}
9187
}

platform_channels/lib/src/pet_list_screen.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ class _PetListScreenState extends State<PetListScreen> {
2525
BasicMessageChannel('stringCodecDemo', StringCodec())
2626
.setMessageHandler((message) async {
2727
if (message == null) {
28-
scaffoldKey.currentState.showSnackBar(
29-
SnackBar(
30-
content:
31-
const Text('An error occurred while adding pet details.')),
32-
);
28+
showSnackBar('An error occurred while adding pet details.', context);
3329
} else {
3430
setState(() {
3531
petListModel = PetListModel.fromJson(message);
@@ -91,10 +87,10 @@ class BuildPetList extends StatelessWidget {
9187
},
9288
);
9389
}
90+
}
9491

95-
void showSnackBar(String message, BuildContext context) {
96-
Scaffold.of(context).showSnackBar(SnackBar(
97-
content: Text(message),
98-
));
99-
}
92+
void showSnackBar(String message, BuildContext context) {
93+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
94+
content: Text(message),
95+
));
10096
}

platform_channels/pubspec.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,56 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.5.0-nullsafety.1"
10+
version: "2.5.0-nullsafety.3"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.1.0-nullsafety.1"
17+
version: "2.1.0-nullsafety.3"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.1.0-nullsafety.3"
24+
version: "1.1.0-nullsafety.5"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.2.0-nullsafety.1"
31+
version: "1.2.0-nullsafety.3"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.1.0-nullsafety.1"
38+
version: "1.1.0-nullsafety.3"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0-nullsafety.3"
45+
version: "1.15.0-nullsafety.5"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
4949
name: cupertino_icons
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.0.0"
52+
version: "1.0.2"
5353
fake_async:
5454
dependency: transitive
5555
description:
5656
name: fake_async
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "1.2.0-nullsafety.1"
59+
version: "1.2.0-nullsafety.3"
6060
flutter:
6161
dependency: "direct main"
6262
description: flutter
@@ -73,21 +73,21 @@ packages:
7373
name: matcher
7474
url: "https://pub.dartlang.org"
7575
source: hosted
76-
version: "0.12.10-nullsafety.1"
76+
version: "0.12.10-nullsafety.3"
7777
meta:
7878
dependency: transitive
7979
description:
8080
name: meta
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "1.3.0-nullsafety.3"
83+
version: "1.3.0-nullsafety.6"
8484
path:
8585
dependency: transitive
8686
description:
8787
name: path
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "1.8.0-nullsafety.1"
90+
version: "1.8.0-nullsafety.3"
9191
pedantic:
9292
dependency: "direct dev"
9393
description:
@@ -106,55 +106,55 @@ packages:
106106
name: source_span
107107
url: "https://pub.dartlang.org"
108108
source: hosted
109-
version: "1.8.0-nullsafety.2"
109+
version: "1.8.0-nullsafety.4"
110110
stack_trace:
111111
dependency: transitive
112112
description:
113113
name: stack_trace
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "1.10.0-nullsafety.1"
116+
version: "1.10.0-nullsafety.6"
117117
stream_channel:
118118
dependency: transitive
119119
description:
120120
name: stream_channel
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "2.1.0-nullsafety.1"
123+
version: "2.1.0-nullsafety.3"
124124
string_scanner:
125125
dependency: transitive
126126
description:
127127
name: string_scanner
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "1.1.0-nullsafety.1"
130+
version: "1.1.0-nullsafety.3"
131131
term_glyph:
132132
dependency: transitive
133133
description:
134134
name: term_glyph
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "1.2.0-nullsafety.1"
137+
version: "1.2.0-nullsafety.3"
138138
test_api:
139139
dependency: transitive
140140
description:
141141
name: test_api
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "0.2.19-nullsafety.2"
144+
version: "0.2.19-nullsafety.6"
145145
typed_data:
146146
dependency: transitive
147147
description:
148148
name: typed_data
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "1.3.0-nullsafety.3"
151+
version: "1.3.0-nullsafety.5"
152152
vector_math:
153153
dependency: transitive
154154
description:
155155
name: vector_math
156156
url: "https://pub.dartlang.org"
157157
source: hosted
158-
version: "2.1.0-nullsafety.3"
158+
version: "2.1.0-nullsafety.5"
159159
sdks:
160-
dart: ">=2.10.0-110 <2.11.0"
160+
dart: ">=2.12.0-0.0 <3.0.0"

0 commit comments

Comments
 (0)