Skip to content

Commit

Permalink
Updated deprecated widgets with new one
Browse files Browse the repository at this point in the history
  • Loading branch information
adarsh-technocrat committed Jan 31, 2021
1 parent 1fae13e commit 8955e13
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 83 deletions.
100 changes: 47 additions & 53 deletions platform_channels/lib/src/method_channel_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,63 @@ class _MethodChannelDemoState extends State<MethodChannelDemo> {
appBar: AppBar(
title: const Text('MethodChannel Demo'),
),
body: Builder(
builder: (context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Value of count is $count',
style: Theme.of(context).textTheme.headline5,
),
SizedBox(
height: 16,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
'Value of count is $count',
style: Theme.of(context).textTheme.headline5,
// Whenever users press the ElevatedButton, it invokes
// Counter.increment method to increment the value of count.
ElevatedButton.icon(
onPressed: () async {
try {
final value = await Counter.increment(counterValue: count);
setState(() => count = value);
} catch (error) {
showErrorMessage(
context,
error.message as String,
);
}
},
icon: Icon(Icons.add),
label: Text('Increment'),
),
SizedBox(
height: 16,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Whenever users press the ElevatedButton, it invokes
// Counter.increment method to increment the value of count.
ElevatedButton.icon(
onPressed: () async {
try {
final value =
await Counter.increment(counterValue: count);
setState(() => count = value);
} catch (error) {
showErrorMessage(
context,
error.message as String,
);
}
},
icon: Icon(Icons.add),
label: Text('Increment'),
),

// Whenever users press the ElevatedButton, it invokes
// Counter.decrement method to decrement the value of count.
ElevatedButton.icon(
onPressed: () async {
try {
final value =
await Counter.decrement(counterValue: count);
setState(() => count = value);
} catch (error) {
showErrorMessage(
context,
error.message as String,
);
}
},
icon: Icon(Icons.remove),
label: Text('Decrement'),
)
],
// Whenever users press the ElevatedButton, it invokes
// Counter.decrement method to decrement the value of count.
ElevatedButton.icon(
onPressed: () async {
try {
final value = await Counter.decrement(counterValue: count);
setState(() => count = value);
} catch (error) {
showErrorMessage(
context,
error.message as String,
);
}
},
icon: Icon(Icons.remove),
label: Text('Decrement'),
)
],
);
},
)
],
),
);
}

void showErrorMessage(BuildContext context, String errorMessage) {
Scaffold.of(context).showSnackBar(SnackBar(
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(errorMessage),
));
}
Expand Down
16 changes: 6 additions & 10 deletions platform_channels/lib/src/pet_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class _PetListScreenState extends State<PetListScreen> {
BasicMessageChannel('stringCodecDemo', StringCodec())
.setMessageHandler((message) async {
if (message == null) {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content:
const Text('An error occurred while adding pet details.')),
);
showSnackBar('An error occurred while adding pet details.', context);
} else {
setState(() {
petListModel = PetListModel.fromJson(message);
Expand Down Expand Up @@ -91,10 +87,10 @@ class BuildPetList extends StatelessWidget {
},
);
}
}

void showSnackBar(String message, BuildContext context) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(message),
));
}
void showSnackBar(String message, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(message),
));
}
40 changes: 20 additions & 20 deletions platform_channels/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.5.0-nullsafety.3"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0-nullsafety.3"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0-nullsafety.5"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0-nullsafety.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0-nullsafety.5"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.2"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -73,21 +73,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10-nullsafety.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.6"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0-nullsafety.3"
pedantic:
dependency: "direct dev"
description:
Expand All @@ -106,55 +106,55 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.0-nullsafety.4"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0-nullsafety.6"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0-nullsafety.3"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0-nullsafety.3"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.2.19-nullsafety.6"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.5"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0-nullsafety.5"
sdks:
dart: ">=2.10.0-110 <2.11.0"
dart: ">=2.12.0-0.0 <3.0.0"

0 comments on commit 8955e13

Please sign in to comment.