From 8955e13572dfa6e989384d2cad0dcbf2e75fa3dc Mon Sep 17 00:00:00 2001 From: adarsh-technocrat Date: Sun, 31 Jan 2021 17:24:36 +0530 Subject: [PATCH] Updated deprecated widgets with new one --- .../lib/src/method_channel_demo.dart | 100 ++++++++---------- .../lib/src/pet_list_screen.dart | 16 ++- platform_channels/pubspec.lock | 40 +++---- 3 files changed, 73 insertions(+), 83 deletions(-) diff --git a/platform_channels/lib/src/method_channel_demo.dart b/platform_channels/lib/src/method_channel_demo.dart index 91e1f4a0738..331c77a35f6 100644 --- a/platform_channels/lib/src/method_channel_demo.dart +++ b/platform_channels/lib/src/method_channel_demo.dart @@ -22,69 +22,63 @@ class _MethodChannelDemoState extends State { 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), )); } diff --git a/platform_channels/lib/src/pet_list_screen.dart b/platform_channels/lib/src/pet_list_screen.dart index b2f4b3cc0e2..909815ae10a 100644 --- a/platform_channels/lib/src/pet_list_screen.dart +++ b/platform_channels/lib/src/pet_list_screen.dart @@ -25,11 +25,7 @@ class _PetListScreenState extends State { 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); @@ -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), + )); } diff --git a/platform_channels/pubspec.lock b/platform_channels/pubspec.lock index ff74a325312..444ac413810 100644 --- a/platform_channels/pubspec.lock +++ b/platform_channels/pubspec.lock @@ -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 @@ -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: @@ -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"