diff --git a/dartpad_codelabs/analysis_options.yaml b/dartpad_codelabs/analysis_options.yaml new file mode 100644 index 0000000000..55717b52e4 --- /dev/null +++ b/dartpad_codelabs/analysis_options.yaml @@ -0,0 +1,9 @@ +include: ../analysis_options.yaml + +analyzer: + strong-mode: + implicit-dynamic: true + +linter: + rules: + avoid_print: false diff --git a/dartpad_codelabs/pubspec.lock b/dartpad_codelabs/pubspec.lock new file mode 100644 index 0000000000..93d91079a0 --- /dev/null +++ b/dartpad_codelabs/pubspec.lock @@ -0,0 +1,160 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.8.2" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.15.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.11" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.3" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" +sdks: + dart: ">=2.15.1 <3.0.0" diff --git a/dartpad_codelabs/pubspec.yaml b/dartpad_codelabs/pubspec.yaml new file mode 100644 index 0000000000..b843876d83 --- /dev/null +++ b/dartpad_codelabs/pubspec.yaml @@ -0,0 +1,19 @@ +name: dartpad_codelabs +description: A new Flutter project. +publish_to: 'none' +version: 1.0.0+1 + +environment: + sdk: ">=2.15.1 <3.0.0" + +dependencies: + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^1.0.0 + +flutter: + uses-material-design: true diff --git a/dartpad_codelabs/src/example_flutter/step_01/snippet.dart b/dartpad_codelabs/src/example_flutter/step_01/snippet.dart index b5dddf4ce7..f2e7f4babf 100644 --- a/dartpad_codelabs/src/example_flutter/step_01/snippet.dart +++ b/dartpad_codelabs/src/example_flutter/step_01/snippet.dart @@ -2,11 +2,16 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// TODO: Remove the following line +// ignore_for_file: unused_field, prefer_const_literals_to_create_immutables + import 'package:flutter/material.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( @@ -15,13 +20,13 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @@ -47,7 +52,7 @@ class _MyHomePageState extends State { body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ // Add Code Here ], ), @@ -55,7 +60,7 @@ class _MyHomePageState extends State { floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', - child: Icon(Icons.add), + child: const Icon(Icons.add), ), ); } diff --git a/dartpad_codelabs/src/example_flutter/step_01/solution.dart b/dartpad_codelabs/src/example_flutter/step_01/solution.dart index 680ebe56b5..53f25753ee 100644 --- a/dartpad_codelabs/src/example_flutter/step_01/solution.dart +++ b/dartpad_codelabs/src/example_flutter/step_01/solution.dart @@ -4,9 +4,11 @@ import 'package:flutter/material.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { return MaterialApp( @@ -15,13 +17,13 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @@ -47,8 +49,8 @@ class _MyHomePageState extends State { body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( + children: [ + const Text( 'You have pushed the button this many times:', ), Text( @@ -61,7 +63,7 @@ class _MyHomePageState extends State { floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', - child: Icon(Icons.add), + child: const Icon(Icons.add), ), ); } diff --git a/dartpad_codelabs/src/example_flutter/step_02/snippet.dart b/dartpad_codelabs/src/example_flutter/step_02/snippet.dart index 7cc3b25a4b..58ee4bfc8a 100644 --- a/dartpad_codelabs/src/example_flutter/step_02/snippet.dart +++ b/dartpad_codelabs/src/example_flutter/step_02/snippet.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; const hostingUrl = 'https://dartpad-workshops-io2021.web.app'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { var title = 'Web Images'; diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_01/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_01/snippet.dart index 523d6dfd4b..99b8750b39 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_01/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_01/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,16 +24,18 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: WeeklyForecastList(), + body: const WeeklyForecastList(), ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -40,7 +44,7 @@ class WeeklyForecastList extends StatelessWidget { return SingleChildScrollView( child: Column( - children: forecasts.map((DailyForecast dailyForecast) { + children: forecasts.map((dailyForecast) { return Card( child: ListTile( leading: Text( diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_02/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_02/snippet.dart index f012d987b3..245617ca70 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_02/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_02/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,27 +24,29 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: WeeklyForecastList(), - ) + body: const WeeklyForecastList(), + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; final List forecasts = Server.getDailyForecastList(); - + // TODO: Let's make this a more efficient Scrollable before we // add more widgets. return SingleChildScrollView( child: Column( - children: forecasts.map((DailyForecast dailyForecast) { + children: forecasts.map((dailyForecast) { return Card( child: ListTile( leading: Text( @@ -61,7 +65,7 @@ class WeeklyForecastList extends StatelessWidget { ), ); }).toList(), - ) + ), ); } } @@ -69,53 +73,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -125,7 +131,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -170,14 +177,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_02/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_02/solution.dart index b16814bdaf..e2288f863a 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_02/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_02/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,16 +24,18 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: WeeklyForecastList(), + body: const WeeklyForecastList(), ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -40,7 +44,7 @@ class WeeklyForecastList extends StatelessWidget { // This Scrollable will lazily load widgets as they come into view. return ListView.builder( itemCount: 7, - itemBuilder: (BuildContext context, int index) { + itemBuilder: (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( child: ListTile( diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_03/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_03/snippet.dart index 704c94bc41..834f64c627 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_03/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_03/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,25 +24,27 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: WeeklyForecastList(), - ) + body: const WeeklyForecastList(), + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; - + // TODO: Incorporate images from DailyForecast return ListView.builder( itemCount: 7, - itemBuilder: (BuildContext context, int index) { + itemBuilder: (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( child: ListTile( @@ -59,7 +63,7 @@ class WeeklyForecastList extends StatelessWidget { ), ), ); - } + }, ); } } @@ -67,53 +71,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -123,7 +129,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -168,14 +175,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_03/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_03/solution.dart index 03ea92caf8..5b5b830f1c 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_03/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_03/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,16 +24,18 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: WeeklyForecastList(), + body: const WeeklyForecastList(), ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -39,7 +43,7 @@ class WeeklyForecastList extends StatelessWidget { return ListView.builder( itemCount: 7, - itemBuilder: (BuildContext context, int index) { + itemBuilder: (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( child: Row( @@ -84,14 +88,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_04/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_04/snippet.dart index 8c906529ed..5fe92c1a87 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_04/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_04/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,26 +24,28 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), // TODO: Add a CustomScrollView - body: WeeklyForecastList(), - ) + body: const WeeklyForecastList(), + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; - + // TODO: Convert this to a SliverList return ListView.builder( itemCount: 7, - itemBuilder: (BuildContext context, int index) { + itemBuilder: (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( child: Row( @@ -56,7 +60,10 @@ class WeeklyForecastList extends StatelessWidget { position: DecorationPosition.foreground, decoration: BoxDecoration( gradient: RadialGradient( - colors: [ Colors.grey[800]!, Colors.transparent ], + colors: [ + Colors.grey[800]!, + Colors.transparent + ], ), ), child: Image.network( @@ -83,14 +90,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, @@ -99,7 +106,7 @@ class WeeklyForecastList extends StatelessWidget { ], ), ); - } + }, ); } } @@ -107,53 +114,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -163,7 +172,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -208,14 +218,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_04/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_04/solution.dart index 5ebb1e6468..d483c52aea 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_04/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_04/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,11 +24,11 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: CustomScrollView( - slivers: [WeeklyForecastList()], + body: const CustomScrollView( + slivers: [WeeklyForecastList()], ), ), ); @@ -34,6 +36,8 @@ class HorizonsApp extends StatelessWidget { } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -41,7 +45,7 @@ class WeeklyForecastList extends StatelessWidget { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { + (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( @@ -87,14 +91,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_05/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_05/snippet.dart index e8147af70d..0bbb169f31 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_05/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_05/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,28 +24,33 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( appBar: AppBar( - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], ), - body: CustomScrollView( + body: const CustomScrollView( // TODO: Add a SliverAppBar - slivers: [ WeeklyForecastList(), ], + slivers: [ + WeeklyForecastList(), + ], ), - ) + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; - + return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - final DailyForecast dailyForecast = Server.getDailyForecastByID(index); + (context, index) { + final DailyForecast dailyForecast = + Server.getDailyForecastByID(index); return Card( child: Row( children: [ @@ -57,7 +64,10 @@ class WeeklyForecastList extends StatelessWidget { position: DecorationPosition.foreground, decoration: BoxDecoration( gradient: RadialGradient( - colors: [ Colors.grey[800]!, Colors.transparent ], + colors: [ + Colors.grey[800]!, + Colors.transparent + ], ), ), child: Image.network( @@ -84,14 +94,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, @@ -110,53 +120,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -166,7 +178,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -211,14 +224,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_05/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_05/solution.dart index 2d2a99faa6..dadd811800 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_05/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_05/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,14 +24,14 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( body: CustomScrollView( - slivers: [ + slivers: [ SliverAppBar( pinned: true, - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], expandedHeight: 200.0, ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), ), @@ -38,6 +40,8 @@ class HorizonsApp extends StatelessWidget { } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -45,7 +49,7 @@ class WeeklyForecastList extends StatelessWidget { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { + (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( @@ -91,14 +95,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_06/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_06/snippet.dart index b39c59f399..91d9f618da 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_06/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_06/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -25,29 +27,32 @@ class HorizonsApp extends StatelessWidget { slivers: [ SliverAppBar( pinned: true, - title: Text('Horizons'), + title: const Text('Horizons'), backgroundColor: Colors.teal[800], expandedHeight: 200.0, // TODO: Add a FlexibleSpaceBar ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), - ) + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; - + return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - final DailyForecast dailyForecast = Server.getDailyForecastByID(index); + (context, index) { + final DailyForecast dailyForecast = + Server.getDailyForecastByID(index); return Card( child: Row( children: [ @@ -61,7 +66,10 @@ class WeeklyForecastList extends StatelessWidget { position: DecorationPosition.foreground, decoration: BoxDecoration( gradient: RadialGradient( - colors: [ Colors.grey[800]!, Colors.transparent ], + colors: [ + Colors.grey[800]!, + Colors.transparent + ], ), ), child: Image.network( @@ -88,14 +96,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, @@ -114,53 +122,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -170,7 +180,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -215,14 +226,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_06/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_06/solution.dart index a5dbb516f3..748d7eed0e 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_06/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_06/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -22,13 +24,13 @@ class HorizonsApp extends StatelessWidget { title: 'Horizons Weather', home: Scaffold( body: CustomScrollView( - slivers: [ + slivers: [ SliverAppBar( pinned: true, backgroundColor: Colors.teal[800], expandedHeight: 200.0, flexibleSpace: FlexibleSpaceBar( - title: Text('Horizons'), + title: const Text('Horizons'), background: DecoratedBox( position: DecorationPosition.foreground, decoration: BoxDecoration( @@ -45,7 +47,7 @@ class HorizonsApp extends StatelessWidget { ), ), ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), ), @@ -54,6 +56,8 @@ class HorizonsApp extends StatelessWidget { } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -61,7 +65,7 @@ class WeeklyForecastList extends StatelessWidget { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { + (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( @@ -107,14 +111,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_07/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_07/snippet.dart index 8f476ab509..5dc5e4effd 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_07/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_07/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -30,14 +32,14 @@ class HorizonsApp extends StatelessWidget { expandedHeight: 200.0, flexibleSpace: FlexibleSpaceBar( // TODO: Explore StretchModes - title: Text('Horizons'), + title: const Text('Horizons'), background: DecoratedBox( position: DecorationPosition.foreground, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.bottomCenter, end: Alignment.center, - colors: [ Colors.teal[800]!, Colors.transparent ], + colors: [Colors.teal[800]!, Colors.transparent], ), ), child: Image.network( @@ -47,24 +49,27 @@ class HorizonsApp extends StatelessWidget { ), ), ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), - ) + ), ); } } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); final TextTheme textTheme = Theme.of(context).textTheme; - + return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - final DailyForecast dailyForecast = Server.getDailyForecastByID(index); + (context, index) { + final DailyForecast dailyForecast = + Server.getDailyForecastByID(index); return Card( child: Row( children: [ @@ -78,7 +83,10 @@ class WeeklyForecastList extends StatelessWidget { position: DecorationPosition.foreground, decoration: BoxDecoration( gradient: RadialGradient( - colors: [ Colors.grey[800]!, Colors.transparent ], + colors: [ + Colors.grey[800]!, + Colors.transparent + ], ), ), child: Image.network( @@ -105,14 +113,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, @@ -131,53 +139,55 @@ class WeeklyForecastList extends StatelessWidget { // -------------------------------------------- // Below this line are helper classes and data. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/getting_started_with_slivers/'; const String headerImage = '${baseAssetURL}assets/header.jpeg'; const Map _kDummyData = { - 0 : DailyForecast( + 0: DailyForecast( id: 0, imageId: '${baseAssetURL}assets/day_0.jpeg', highTemp: 73, lowTemp: 52, - description: 'Partly cloudy in the morning, with sun appearing in the afternoon.', + description: + 'Partly cloudy in the morning, with sun appearing in the afternoon.', ), - 1 : DailyForecast( + 1: DailyForecast( id: 1, imageId: '${baseAssetURL}assets/day_1.jpeg', highTemp: 70, lowTemp: 50, description: 'Partly sunny.', ), - 2 : DailyForecast( + 2: DailyForecast( id: 2, imageId: '${baseAssetURL}assets/day_2.jpeg', highTemp: 71, lowTemp: 55, description: 'Party cloudy.', ), - 3 : DailyForecast( + 3: DailyForecast( id: 3, imageId: '${baseAssetURL}assets/day_3.jpeg', highTemp: 74, lowTemp: 60, description: 'Thunderstorms in the evening.', ), - 4 : DailyForecast( + 4: DailyForecast( id: 4, imageId: '${baseAssetURL}assets/day_4.jpeg', highTemp: 67, lowTemp: 60, description: 'Severe thunderstorm warning.', ), - 5 : DailyForecast( + 5: DailyForecast( id: 5, imageId: '${baseAssetURL}assets/day_5.jpeg', highTemp: 73, lowTemp: 57, description: 'Cloudy with showers in the morning.', ), - 6 : DailyForecast( + 6: DailyForecast( id: 6, imageId: '${baseAssetURL}assets/day_6.jpeg', highTemp: 75, @@ -187,7 +197,8 @@ const Map _kDummyData = { }; class Server { - static List getDailyForecastList() => _kDummyData.values.toList(); + static List getDailyForecastList() => + _kDummyData.values.toList(); static DailyForecast getDailyForecastByID(int id) { assert(id >= 0 && id <= 6); @@ -232,14 +243,19 @@ class ConstantScrollBehavior extends ScrollBehavior { const ConstantScrollBehavior(); @override - Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildScrollbar( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override - Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) => child; + Widget buildOverscrollIndicator( + BuildContext context, Widget child, ScrollableDetails details) => + child; @override TargetPlatform getPlatform(BuildContext context) => TargetPlatform.macOS; @override - ScrollPhysics getScrollPhysics(BuildContext context) => const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); + ScrollPhysics getScrollPhysics(BuildContext context) => + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()); } diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_07/solution.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_07/solution.dart index fcb7ae514c..653a7cdd02 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_07/solution.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_07/solution.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -33,12 +35,12 @@ class HorizonsApp extends StatelessWidget { backgroundColor: Colors.teal[800], expandedHeight: 200.0, flexibleSpace: FlexibleSpaceBar( - stretchModes: [ + stretchModes: const [ StretchMode.zoomBackground, StretchMode.fadeTitle, StretchMode.blurBackground, ], - title: Text('Horizons'), + title: const Text('Horizons'), background: DecoratedBox( position: DecorationPosition.foreground, decoration: BoxDecoration( @@ -55,7 +57,7 @@ class HorizonsApp extends StatelessWidget { ), ), ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), ), @@ -64,6 +66,8 @@ class HorizonsApp extends StatelessWidget { } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -71,7 +75,7 @@ class WeeklyForecastList extends StatelessWidget { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { + (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( @@ -117,14 +121,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/getting_started_with_slivers/step_08/snippet.dart b/dartpad_codelabs/src/getting_started_with_slivers/step_08/snippet.dart index fcb7ae514c..653a7cdd02 100644 --- a/dartpad_codelabs/src/getting_started_with_slivers/step_08/snippet.dart +++ b/dartpad_codelabs/src/getting_started_with_slivers/step_08/snippet.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; void main() { - runApp(HorizonsApp()); + runApp(const HorizonsApp()); } class HorizonsApp extends StatelessWidget { + const HorizonsApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -33,12 +35,12 @@ class HorizonsApp extends StatelessWidget { backgroundColor: Colors.teal[800], expandedHeight: 200.0, flexibleSpace: FlexibleSpaceBar( - stretchModes: [ + stretchModes: const [ StretchMode.zoomBackground, StretchMode.fadeTitle, StretchMode.blurBackground, ], - title: Text('Horizons'), + title: const Text('Horizons'), background: DecoratedBox( position: DecorationPosition.foreground, decoration: BoxDecoration( @@ -55,7 +57,7 @@ class HorizonsApp extends StatelessWidget { ), ), ), - WeeklyForecastList(), + const WeeklyForecastList(), ], ), ), @@ -64,6 +66,8 @@ class HorizonsApp extends StatelessWidget { } class WeeklyForecastList extends StatelessWidget { + const WeeklyForecastList({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { final DateTime currentDate = DateTime.now(); @@ -71,7 +75,7 @@ class WeeklyForecastList extends StatelessWidget { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { + (context, index) { final DailyForecast dailyForecast = Server.getDailyForecastByID(index); return Card( @@ -117,14 +121,14 @@ class WeeklyForecastList extends StatelessWidget { dailyForecast.getWeekday(currentDate.weekday), style: textTheme.headline4, ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Text(dailyForecast.description), ], ), ), ), Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Text( '${dailyForecast.highTemp} | ${dailyForecast.lowTemp} F', style: textTheme.subtitle1, diff --git a/dartpad_codelabs/src/inherited_widget/intro/snippet.dart b/dartpad_codelabs/src/inherited_widget/intro/snippet.dart index 1dbee81e42..c6b6aac36c 100644 --- a/dartpad_codelabs/src/inherited_widget/intro/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/intro/snippet.dart @@ -1,4 +1,3 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; final GlobalKey shoppingCart = @@ -8,7 +7,7 @@ final GlobalKey productList = void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), @@ -17,7 +16,7 @@ void main() { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -51,7 +50,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -63,9 +62,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), onPressed: _handleSearch), + icon: const Icon(Icons.search), + onPressed: _handleSearch), suffixIcon: IconButton( - icon: Icon(Icons.close), onPressed: _toggleSearch), + icon: const Icon(Icons.close), + onPressed: _toggleSearch), ), ) : null, @@ -73,7 +74,7 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), ShoppingCartIcon(key: shoppingCart), ], @@ -90,7 +91,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); @@ -108,13 +109,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -128,7 +129,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -141,7 +142,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -194,7 +195,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -219,32 +220,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_01/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_01/snippet.dart index 4c4486d10e..880fdb5eb2 100644 --- a/dartpad_codelabs/src/inherited_widget/step_01/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_01/snippet.dart @@ -1,37 +1,38 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -final GlobalKey shoppingCart = GlobalKey(); -final GlobalKey productList = GlobalKey(); +final GlobalKey shoppingCart = + GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), - ) + ), ); } class AppState { // TODO: fill in this data structure. - AppState copyWith({ - //.. - }) { + AppState copyWith( + //.. + ) { // TODO: implement copy method. + throw UnimplementedError(); } } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -47,7 +48,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -57,24 +59,31 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') - ), + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png')), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), ShoppingCartIcon(key: shoppingCart), ], backgroundColor: Colors.white, @@ -90,7 +99,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); } @@ -106,13 +115,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -126,7 +135,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -139,7 +148,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -147,7 +156,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -189,7 +198,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -206,38 +215,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -253,19 +267,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -274,16 +292,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -300,8 +319,9 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) + if (filter == null) { return kDummyData.keys.toList(); + } final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -317,7 +337,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_01/solution.dart b/dartpad_codelabs/src/inherited_widget/step_01/solution.dart index c3ce86a5ee..75848a64f5 100644 --- a/dartpad_codelabs/src/inherited_widget/step_01/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_01/solution.dart @@ -1,4 +1,3 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; final GlobalKey shoppingCart = @@ -8,7 +7,7 @@ final GlobalKey productList = void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), @@ -37,7 +36,7 @@ class AppState { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -71,7 +70,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -83,11 +82,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -97,7 +96,7 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), ShoppingCartIcon(key: shoppingCart), ], @@ -114,7 +113,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); @@ -132,13 +131,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -152,7 +151,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -165,7 +164,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -218,7 +217,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -243,32 +242,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_02/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_02/snippet.dart index 146ab18f30..7bb583f9af 100644 --- a/dartpad_codelabs/src/inherited_widget/step_02/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_02/snippet.dart @@ -1,17 +1,17 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; -final GlobalKey shoppingCart = GlobalKey(); -final GlobalKey productList = GlobalKey(); +final GlobalKey shoppingCart = + GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), - ) + ), ); } @@ -38,24 +38,28 @@ class AppState { class AppStateScope extends InheritedWidget { // TODO: implement this class. + const AppStateScope({Key? key, required Widget child}) + : super(key: key, child: child); + static AppState of(BuildContext context) { // TODO: implement this method. + throw UnimplementedError(); } @override bool updateShouldNotify(AppStateScope oldWidget) { // TODO: implement this method. + throw UnimplementedError(); } } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -71,7 +75,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -81,24 +86,32 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), ShoppingCartIcon(key: shoppingCart), ], backgroundColor: Colors.white, @@ -114,7 +127,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); } @@ -130,13 +143,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -150,7 +163,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -163,7 +176,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -171,7 +184,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -213,7 +226,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -230,38 +243,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -277,19 +295,26 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black), + ), + TextSpan( + text: 'Capture your world.', + style: TextStyle(color: Colors.blue), + ), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -298,16 +323,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -324,8 +350,9 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) + if (filter == null) { return kDummyData.keys.toList(); + } final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -341,7 +368,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_02/solution.dart b/dartpad_codelabs/src/inherited_widget/step_02/solution.dart index 825eb5b58c..23c05f89af 100644 --- a/dartpad_codelabs/src/inherited_widget/step_02/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_02/solution.dart @@ -1,6 +1,4 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; final GlobalKey shoppingCart = GlobalKey(); @@ -9,7 +7,7 @@ final GlobalKey productList = void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), @@ -38,7 +36,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -54,7 +52,7 @@ class AppStateScope extends InheritedWidget { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -88,7 +86,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -100,11 +98,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -114,7 +112,7 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), ShoppingCartIcon(key: shoppingCart), ], @@ -131,7 +129,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); @@ -149,13 +147,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -169,7 +167,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -182,7 +180,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -235,7 +233,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -260,32 +258,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_03/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_03/snippet.dart index 7984bcd9b7..4d80c133c0 100644 --- a/dartpad_codelabs/src/inherited_widget/step_03/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_03/snippet.dart @@ -1,17 +1,20 @@ -import 'package:flutter/widgets.dart'; +// TODO: Remove the following line +// ignore_for_file: prefer_final_fields, unused_field + import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; -final GlobalKey shoppingCart = GlobalKey(); -final GlobalKey productList = GlobalKey(); +final GlobalKey shoppingCart = + GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), - ) + ), ); } @@ -36,7 +39,8 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); + const AppStateScope(this.data, {Key? key, required Widget child}) + : super(key: key, child: child); final AppState data; @@ -51,13 +55,15 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; static AppStateWidgetState of(BuildContext context) { // TODO: implement this method + throw UnimplementedError(); } + @override AppStateWidgetState createState() => AppStateWidgetState(); } @@ -82,17 +88,17 @@ class AppStateWidgetState extends State { @override Widget build(BuildContext context) { // TODO: implement this method + throw UnimplementedError(); } } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -108,7 +114,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -118,24 +125,32 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), ShoppingCartIcon(key: shoppingCart), ], backgroundColor: Colors.white, @@ -151,7 +166,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); } @@ -167,13 +182,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -187,7 +202,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -200,7 +215,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -208,7 +223,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -250,7 +265,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -267,38 +282,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -314,19 +334,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -335,16 +359,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -361,8 +386,7 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) - return kDummyData.keys.toList(); + if (filter == null) return kDummyData.keys.toList(); final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -378,7 +402,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_03/solution.dart b/dartpad_codelabs/src/inherited_widget/step_03/solution.dart index 6ca2dc7dfc..b215e492dd 100644 --- a/dartpad_codelabs/src/inherited_widget/step_03/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_03/solution.dart @@ -1,6 +1,4 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; final GlobalKey shoppingCart = GlobalKey(); @@ -9,7 +7,7 @@ final GlobalKey productList = void main() { runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), @@ -38,7 +36,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -54,7 +52,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -115,7 +113,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -149,7 +147,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -161,11 +159,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -175,7 +173,7 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), ShoppingCartIcon(key: shoppingCart), ], @@ -192,7 +190,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); @@ -210,13 +208,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -230,7 +228,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -243,7 +241,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -296,7 +294,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -321,32 +319,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_04/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_04/snippet.dart index 02c589a882..9243379ecf 100644 --- a/dartpad_codelabs/src/inherited_widget/step_04/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_04/snippet.dart @@ -1,18 +1,18 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; -final GlobalKey shoppingCart = GlobalKey(); -final GlobalKey productList = GlobalKey(); +final GlobalKey shoppingCart = + GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { // TODO: insert AppStateWidget above MaterialApp. runApp( - MaterialApp( + const MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', home: MyStorePage(), - ) + ), ); } @@ -37,7 +37,8 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); + const AppStateScope(this.data, {Key? key, required Widget child}) + : super(key: key, child: child); final AppState data; @@ -52,7 +53,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -113,13 +114,12 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -135,7 +135,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -145,24 +146,32 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), ShoppingCartIcon(key: shoppingCart), ], backgroundColor: Colors.white, @@ -178,7 +187,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); } @@ -194,13 +203,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -214,7 +223,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -227,7 +236,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -235,7 +244,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -277,7 +286,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -294,38 +303,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -341,19 +355,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -362,16 +380,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -388,8 +407,7 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) - return kDummyData.keys.toList(); + if (filter == null) return kDummyData.keys.toList(); final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -405,7 +423,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_04/solution.dart b/dartpad_codelabs/src/inherited_widget/step_04/solution.dart index 8a68f94c47..53c8c3ce5c 100644 --- a/dartpad_codelabs/src/inherited_widget/step_04/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_04/solution.dart @@ -1,6 +1,4 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; final GlobalKey shoppingCart = GlobalKey(); @@ -9,7 +7,7 @@ final GlobalKey productList = void main() { runApp( - AppStateWidget( + const AppStateWidget( child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', @@ -40,7 +38,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -56,7 +54,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -117,7 +115,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -151,7 +149,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -163,11 +161,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -177,7 +175,7 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), ShoppingCartIcon(key: shoppingCart), ], @@ -194,7 +192,7 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); @@ -212,13 +210,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -232,7 +230,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -245,7 +243,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -298,7 +296,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -323,32 +321,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_05/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_05/snippet.dart index e5c124b577..01af94184e 100644 --- a/dartpad_codelabs/src/inherited_widget/step_05/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_05/snippet.dart @@ -1,20 +1,20 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; // TODO: remove the usage of shoppingCart Globalkey. -final GlobalKey shoppingCart = GlobalKey(); -final GlobalKey productList = GlobalKey(); +final GlobalKey shoppingCart = + GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { runApp( - AppStateWidget( - child: MaterialApp( - debugShowCheckedModeBanner: false, - title: 'Store', - home: MyStorePage(), - ) - ) + const AppStateWidget( + child: MaterialApp( + debugShowCheckedModeBanner: false, + title: 'Store', + home: MyStorePage(), + ), + ), ); } @@ -39,7 +39,8 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); + const AppStateScope(this.data, {Key? key, required Widget child}) + : super(key: key, child: child); final AppState data; @@ -54,7 +55,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -115,13 +116,12 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -137,7 +137,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -147,24 +148,32 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), ShoppingCartIcon(key: shoppingCart), ], backgroundColor: Colors.white, @@ -181,7 +190,7 @@ class MyStorePageState extends State { // TODO: convert ShoppingCartIcon into StatelessWidget. class ShoppingCartIcon extends StatefulWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override ShoppingCartIconState createState() => ShoppingCartIconState(); } @@ -197,13 +206,13 @@ class ShoppingCartIconState extends State { @override Widget build(BuildContext context) { - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -217,7 +226,7 @@ class ShoppingCartIconState extends State { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -230,7 +239,7 @@ class ShoppingCartIconState extends State { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -238,7 +247,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -280,7 +289,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -297,38 +306,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -344,19 +358,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -365,16 +383,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -391,8 +410,7 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) - return kDummyData.keys.toList(); + if (filter == null) return kDummyData.keys.toList(); final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -408,7 +426,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_05/solution.dart b/dartpad_codelabs/src/inherited_widget/step_05/solution.dart index c408a97be6..b903bbf47f 100644 --- a/dartpad_codelabs/src/inherited_widget/step_05/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_05/solution.dart @@ -1,13 +1,11 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; final GlobalKey productList = GlobalKey(); void main() { runApp( - AppStateWidget( + const AppStateWidget( child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', @@ -38,7 +36,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -54,7 +52,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -115,7 +113,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -149,7 +147,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -161,11 +159,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -175,9 +173,9 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), - ShoppingCartIcon(), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, @@ -192,18 +190,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -217,7 +215,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -230,7 +228,7 @@ class ShoppingCartIcon extends StatelessWidget { } class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); @@ -281,7 +279,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -306,32 +304,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_06/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_06/snippet.dart index 8c50f6632e..31d36fcb97 100644 --- a/dartpad_codelabs/src/inherited_widget/step_06/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_06/snippet.dart @@ -1,19 +1,18 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; // TODO: remove the usage of productList Globalkey. -final GlobalKey productList = GlobalKey(); +final GlobalKey productList = + GlobalKey(); void main() { runApp( - AppStateWidget( - child: MaterialApp( - debugShowCheckedModeBanner: false, - title: 'Store', - home: MyStorePage(), - ) - ) + const AppStateWidget( + child: MaterialApp( + debugShowCheckedModeBanner: false, + title: 'Store', + home: MyStorePage(), + ), + ), ); } @@ -38,7 +37,8 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); + const AppStateScope(this.data, {Key? key, required Widget child}) + : super(key: key, child: child); final AppState data; @@ -53,7 +53,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -114,13 +114,12 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -136,7 +135,8 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); final String filter = _controller.text; - productList.currentState!.productList = Server.getProductList(filter: filter); + productList.currentState!.productList = + Server.getProductList(filter: filter); } @override @@ -146,25 +146,33 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch - ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), + ? TextField( + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), ) - ) - : null, + : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), - ShoppingCartIcon(), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, @@ -179,18 +187,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -204,7 +212,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -218,7 +226,7 @@ class ShoppingCartIcon extends StatelessWidget { // TODO: convert ProductListWidget into StatelessWidget. class ProductListWidget extends StatefulWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); @override ProductListWidgetState createState() => ProductListWidgetState(); } @@ -226,7 +234,7 @@ class ProductListWidget extends StatefulWidget { class ProductListWidgetState extends State { List get productList => _productList; List _productList = Server.getProductList(); - set productList (List value) { + set productList(List value) { setState(() { _productList = value; }); @@ -266,7 +274,7 @@ class ProductListWidgetState extends State { } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -283,38 +291,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -330,19 +343,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -351,16 +368,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -377,8 +395,7 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) - return kDummyData.keys.toList(); + if (filter == null) return kDummyData.keys.toList(); final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -394,7 +411,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_06/solution.dart b/dartpad_codelabs/src/inherited_widget/step_06/solution.dart index 9debdb207f..ebfebedf1d 100644 --- a/dartpad_codelabs/src/inherited_widget/step_06/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_06/solution.dart @@ -1,10 +1,8 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; void main() { runApp( - AppStateWidget( + const AppStateWidget( child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', @@ -35,7 +33,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -51,7 +49,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -112,7 +110,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -133,7 +131,6 @@ class MyStorePageState extends State { void _handleSearch() { _focusNode.unfocus(); - final String filter = _controller.text; } @override @@ -143,7 +140,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -155,11 +152,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: _handleSearch, ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: _toggleSearch, ), ), @@ -169,14 +166,14 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: _toggleSearch, - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), - ShoppingCartIcon(), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, ), - SliverToBoxAdapter( + const SliverToBoxAdapter( child: ProductListWidget(), ), ], @@ -186,18 +183,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -211,7 +208,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -224,7 +221,7 @@ class ShoppingCartIcon extends StatelessWidget { } class ProductListWidget extends StatelessWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); void _handleAddToCart(String id, BuildContext context) { AppStateWidget.of(context).addToCart(id); @@ -247,15 +244,14 @@ class ProductListWidget extends StatelessWidget { Widget build(BuildContext context) { final List productList = AppStateScope.of(context).productList; return Column( - children: productList - .map((String id) => _buildProductTile(id, context)) - .toList(), + children: + productList.map((id) => _buildProductTile(id, context)).toList(), ); } } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -280,32 +276,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_07/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_07/snippet.dart index 1eb478efb9..11350ac5b4 100644 --- a/dartpad_codelabs/src/inherited_widget/step_07/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_07/snippet.dart @@ -1,16 +1,17 @@ -import 'package:flutter/widgets.dart'; +// TODO: Remove the following line +// ignore_for_file: unused_local_variable + import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; void main() { runApp( - AppStateWidget( - child: MaterialApp( - debugShowCheckedModeBanner: false, - title: 'Store', - home: MyStorePage(), - ) - ) + const AppStateWidget( + child: MaterialApp( + debugShowCheckedModeBanner: false, + title: 'Store', + home: MyStorePage(), + ), + ), ); } @@ -35,7 +36,8 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); + const AppStateScope(this.data, {Key? key, required Widget child}) + : super(key: key, child: child); final AppState data; @@ -50,7 +52,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -111,13 +113,12 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); } class MyStorePageState extends State { - bool _inSearch = false; final TextEditingController _controller = TextEditingController(); final FocusNode _focusNode = FocusNode(); @@ -143,30 +144,38 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), - child: Image.network('$baseAssetURL/google-logo.png') + padding: const EdgeInsets.all(16.0), + child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch ? TextField( - autofocus: true, - focusNode: _focusNode, - controller: _controller, - onSubmitted: (_) => _handleSearch(), - decoration: InputDecoration( - hintText: 'Search Google Store', - prefixIcon: IconButton(icon: Icon(Icons.search), onPressed: _handleSearch), - suffixIcon: IconButton(icon: Icon(Icons.close), onPressed: _toggleSearch), - ) - ) + autofocus: true, + focusNode: _focusNode, + controller: _controller, + onSubmitted: (_) => _handleSearch(), + decoration: InputDecoration( + hintText: 'Search Google Store', + prefixIcon: IconButton( + icon: const Icon(Icons.search), + onPressed: _handleSearch), + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: _toggleSearch), + ), + ) : null, actions: [ - if (!_inSearch) IconButton(onPressed: _toggleSearch, icon: Icon(Icons.search, color: Colors.black)), - ShoppingCartIcon(), + if (!_inSearch) + IconButton( + onPressed: _toggleSearch, + icon: const Icon(Icons.search, color: Colors.black), + ), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, ), - SliverToBoxAdapter( + const SliverToBoxAdapter( child: ProductListWidget(), ), ], @@ -176,18 +185,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -201,7 +210,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -214,7 +223,7 @@ class ShoppingCartIcon extends StatelessWidget { } class ProductListWidget extends StatelessWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); void _handleAddToCart(String id, BuildContext context) { AppStateWidget.of(context).addToCart(id); @@ -237,13 +246,14 @@ class ProductListWidget extends StatelessWidget { Widget build(BuildContext context) { final List productList = AppStateScope.of(context).productList; return Column( - children: productList.map((String id) =>_buildProductTile(id, context)).toList(), + children: + productList.map((id) => _buildProductTile(id, context)).toList(), ); } } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -260,38 +270,43 @@ class ProductTile extends StatelessWidget { Color getButtonColor(Set states) { return purchased ? Colors.grey : Colors.black; } + BorderSide getButtonSide(Set states) { return BorderSide( color: purchased ? Colors.grey : Colors.black, ); } + return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( - child: purchased ? const Text("Remove from cart"): const Text("Add to cart"), + child: purchased + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), + foregroundColor: + MaterialStateProperty.resolveWith(getButtonColor), side: MaterialStateProperty.resolveWith(getButtonSide), ), onPressed: purchased ? onRemoveFromCart : onAddToCart, @@ -307,19 +322,23 @@ class ProductTile extends StatelessWidget { // The code below is for the dummy server, and you should not need to modify it // in this workshop. -const String baseAssetURL = 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; +const String baseAssetURL = + 'https://dartpad-workshops-io2021.web.app/inherited_widget/assets'; const Map kDummyData = { - '0' : Product( + '0': Product( id: '0', title: 'Explore Pixel phones', description: TextSpan(children: [ - TextSpan(text: 'Capture the details.\n', style: TextStyle(color: Colors.black)), - TextSpan(text: 'Capture your world.', style: TextStyle(color: Colors.blue)), + TextSpan( + text: 'Capture the details.\n', + style: TextStyle(color: Colors.black)), + TextSpan( + text: 'Capture your world.', style: TextStyle(color: Colors.blue)), ]), pictureURL: '$baseAssetURL/pixels.png', ), - '1' : Product( + '1': Product( id: '1', title: 'Nest Audio', description: TextSpan(children: [ @@ -328,16 +347,17 @@ const Map kDummyData = { ]), pictureURL: '$baseAssetURL/nest.png', ), - '2' : Product( + '2': Product( id: '2', title: 'Nest Audio Entertainment packages', description: TextSpan(children: [ - TextSpan(text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), + TextSpan( + text: 'Built for music.\n', style: TextStyle(color: Colors.orange)), TextSpan(text: 'Made for you.', style: TextStyle(color: Colors.black)), ]), pictureURL: '$baseAssetURL/nest-audio-packages.png', ), - '3' : Product( + '3': Product( id: '3', title: 'Nest Home Security packages', description: TextSpan(children: [ @@ -354,8 +374,7 @@ class Server { } static List getProductList({String? filter}) { - if (filter == null) - return kDummyData.keys.toList(); + if (filter == null) return kDummyData.keys.toList(); final List ids = []; for (final Product product in kDummyData.values) { if (product.title.toLowerCase().contains(filter.toLowerCase())) { @@ -371,7 +390,7 @@ class Product { required this.id, required this.pictureURL, required this.title, - required this.description + required this.description, }); final String id; diff --git a/dartpad_codelabs/src/inherited_widget/step_07/solution.dart b/dartpad_codelabs/src/inherited_widget/step_07/solution.dart index a7fc12f7aa..d79c63ada7 100644 --- a/dartpad_codelabs/src/inherited_widget/step_07/solution.dart +++ b/dartpad_codelabs/src/inherited_widget/step_07/solution.dart @@ -1,10 +1,8 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; void main() { runApp( - AppStateWidget( + const AppStateWidget( child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', @@ -35,7 +33,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -51,7 +49,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -112,7 +110,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -145,7 +143,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -157,11 +155,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: () => _handleSearch(context), ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: () => _toggleSearch(context), ), ), @@ -171,14 +169,14 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: () => _toggleSearch(context), - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), - ShoppingCartIcon(), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, ), - SliverToBoxAdapter( + const SliverToBoxAdapter( child: ProductListWidget(), ), ], @@ -188,18 +186,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -213,7 +211,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -226,7 +224,7 @@ class ShoppingCartIcon extends StatelessWidget { } class ProductListWidget extends StatelessWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); void _handleAddToCart(String id, BuildContext context) { AppStateWidget.of(context).addToCart(id); @@ -249,15 +247,14 @@ class ProductListWidget extends StatelessWidget { Widget build(BuildContext context) { final List productList = AppStateScope.of(context).productList; return Column( - children: productList - .map((String id) => _buildProductTile(id, context)) - .toList(), + children: + productList.map((id) => _buildProductTile(id, context)).toList(), ); } } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -282,32 +279,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/inherited_widget/step_08/snippet.dart b/dartpad_codelabs/src/inherited_widget/step_08/snippet.dart index a7fc12f7aa..d79c63ada7 100644 --- a/dartpad_codelabs/src/inherited_widget/step_08/snippet.dart +++ b/dartpad_codelabs/src/inherited_widget/step_08/snippet.dart @@ -1,10 +1,8 @@ -import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; void main() { runApp( - AppStateWidget( + const AppStateWidget( child: MaterialApp( debugShowCheckedModeBanner: false, title: 'Store', @@ -35,7 +33,7 @@ class AppState { } class AppStateScope extends InheritedWidget { - AppStateScope(this.data, {Key? key, required Widget child}) + const AppStateScope(this.data, {Key? key, required Widget child}) : super(key: key, child: child); final AppState data; @@ -51,7 +49,7 @@ class AppStateScope extends InheritedWidget { } class AppStateWidget extends StatefulWidget { - AppStateWidget({required this.child}); + const AppStateWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -112,7 +110,7 @@ class AppStateWidgetState extends State { } class MyStorePage extends StatefulWidget { - MyStorePage({Key? key}) : super(key: key); + const MyStorePage({Key? key}) : super(key: key); @override MyStorePageState createState() => MyStorePageState(); @@ -145,7 +143,7 @@ class MyStorePageState extends State { slivers: [ SliverAppBar( leading: Padding( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), child: Image.network('$baseAssetURL/google-logo.png'), ), title: _inSearch @@ -157,11 +155,11 @@ class MyStorePageState extends State { decoration: InputDecoration( hintText: 'Search Google Store', prefixIcon: IconButton( - icon: Icon(Icons.search), + icon: const Icon(Icons.search), onPressed: () => _handleSearch(context), ), suffixIcon: IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), onPressed: () => _toggleSearch(context), ), ), @@ -171,14 +169,14 @@ class MyStorePageState extends State { if (!_inSearch) IconButton( onPressed: () => _toggleSearch(context), - icon: Icon(Icons.search, color: Colors.black), + icon: const Icon(Icons.search, color: Colors.black), ), - ShoppingCartIcon(), + const ShoppingCartIcon(), ], backgroundColor: Colors.white, pinned: true, ), - SliverToBoxAdapter( + const SliverToBoxAdapter( child: ProductListWidget(), ), ], @@ -188,18 +186,18 @@ class MyStorePageState extends State { } class ShoppingCartIcon extends StatelessWidget { - ShoppingCartIcon({Key? key}) : super(key: key); + const ShoppingCartIcon({Key? key}) : super(key: key); @override Widget build(BuildContext context) { final Set itemsInCart = AppStateScope.of(context).itemsInCart; - final bool hasPurchase = itemsInCart.length > 0; + final bool hasPurchase = itemsInCart.isNotEmpty; return Stack( alignment: Alignment.center, children: [ Padding( padding: EdgeInsets.only(right: hasPurchase ? 17.0 : 10.0), - child: Icon( + child: const Icon( Icons.shopping_cart, color: Colors.black, ), @@ -213,7 +211,7 @@ class ShoppingCartIcon extends StatelessWidget { foregroundColor: Colors.white, child: Text( itemsInCart.length.toString(), - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 12.0, ), @@ -226,7 +224,7 @@ class ShoppingCartIcon extends StatelessWidget { } class ProductListWidget extends StatelessWidget { - ProductListWidget({Key? key}) : super(key: key); + const ProductListWidget({Key? key}) : super(key: key); void _handleAddToCart(String id, BuildContext context) { AppStateWidget.of(context).addToCart(id); @@ -249,15 +247,14 @@ class ProductListWidget extends StatelessWidget { Widget build(BuildContext context) { final List productList = AppStateScope.of(context).productList; return Column( - children: productList - .map((String id) => _buildProductTile(id, context)) - .toList(), + children: + productList.map((id) => _buildProductTile(id, context)).toList(), ); } } class ProductTile extends StatelessWidget { - ProductTile({ + const ProductTile({ Key? key, required this.product, required this.purchased, @@ -282,32 +279,32 @@ class ProductTile extends StatelessWidget { } return Container( - margin: EdgeInsets.symmetric( + margin: const EdgeInsets.symmetric( vertical: 15, horizontal: 40, ), - color: Color(0xfff8f8f8), + color: const Color(0xfff8f8f8), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Text(product.title), ), Text.rich( product.description, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ), ), Padding( - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: OutlinedButton( child: purchased - ? const Text("Remove from cart") - : const Text("Add to cart"), + ? const Text('Remove from cart') + : const Text('Add to cart'), style: ButtonStyle( foregroundColor: MaterialStateProperty.resolveWith(getButtonColor), diff --git a/dartpad_codelabs/src/null_safety_workshop/step_01/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_01/snippet.dart index ee20e646d5..6702552890 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_01/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_01/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: invalid_assignment + void main() { int a; a = null; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_02/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_02/snippet.dart index ee20e646d5..6702552890 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_02/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_02/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: invalid_assignment + void main() { int a; a = null; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_03/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_03/snippet.dart index 0d6ff92865..12b37248fc 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_03/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_03/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: list_element_type_not_assignable, not_assigned_potentially_non_nullable_local_variable + void main() { List aListOfStrings = ['one', 'two', 'three']; List aNullableListOfStrings; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_04/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_04/snippet.dart index 708f205241..3be88ba31c 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_04/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_04/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: invalid_assignment, unchecked_use_of_nullable_value + int? couldReturnNullButDoesnt() => -3; void main() { diff --git a/dartpad_codelabs/src/null_safety_workshop/step_05/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_05/snippet.dart index a7f07f6153..65acc28422 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_05/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_05/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: missing_default_value_for_parameter + int addThreeValues({ int first, int second, diff --git a/dartpad_codelabs/src/null_safety_workshop/step_06/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_06/snippet.dart index 20632d193d..97a71be6d5 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_06/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_06/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: unchecked_use_of_nullable_value + void main() { String? text; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_07/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_07/snippet.dart index d5567dd87f..1453b91586 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_07/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_07/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: unchecked_use_of_nullable_value + int getLength(String? str) { // Add null check here diff --git a/dartpad_codelabs/src/null_safety_workshop/step_08/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_08/snippet.dart index 6d3efb71f4..c4a45a2a40 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_08/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_08/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: unchecked_use_of_nullable_value + int getLength(String? str) { // Try throwing an exception here if `str` is null. diff --git a/dartpad_codelabs/src/null_safety_workshop/step_09/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_09/snippet.dart index dd5a07bf4e..bccca88686 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_09/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_09/snippet.dart @@ -1,8 +1,10 @@ +// TODO: Remove the following line +// ignore_for_file: argument_type_not_assignable + import 'dart:math'; class RandomStringProvider { - String? get value => - Random().nextBool() ? 'A String!' : null; + String? get value => Random().nextBool() ? 'A String!' : null; } void printString(String str) => print(str); diff --git a/dartpad_codelabs/src/null_safety_workshop/step_10/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_10/snippet.dart index 8b70796e4b..b9e8cace7f 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_10/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_10/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: argument_type_not_assignable + import 'dart:math'; class StringProvider { @@ -6,11 +9,10 @@ class StringProvider { class RandomStringProvider extends StringProvider { @override - void set value(String? v) {} + set value(String? v) {} @override - String? get value => - Random().nextBool() ? 'A String!' : null; + String? get value => Random().nextBool() ? 'A String!' : null; } void printString(String str) => print(str); diff --git a/dartpad_codelabs/src/null_safety_workshop/step_10/solution.dart b/dartpad_codelabs/src/null_safety_workshop/step_10/solution.dart index e8b6b5390c..10db4a715d 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_10/solution.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_10/solution.dart @@ -6,7 +6,7 @@ class StringProvider { class RandomStringProvider extends StringProvider { @override - void set value(String? v) {} + set value(String? v) {} @override String? get value => Random().nextBool() ? 'A String!' : null; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_11/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_11/snippet.dart index 5d9c93c39f..66000ba5a0 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_11/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_11/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: not_initialized_non_nullable_instance_field + class Meal { String description; diff --git a/dartpad_codelabs/src/null_safety_workshop/step_12/snippet.dart b/dartpad_codelabs/src/null_safety_workshop/step_12/snippet.dart index 93060ebecb..91bf6b1b63 100644 --- a/dartpad_codelabs/src/null_safety_workshop/step_12/snippet.dart +++ b/dartpad_codelabs/src/null_safety_workshop/step_12/snippet.dart @@ -1,3 +1,6 @@ +// TODO: Remove the following line +// ignore_for_file: final_not_initialized, assignment_to_final + class Team { final Coach coach; } diff --git a/flutter_ci_script_beta.sh b/flutter_ci_script_beta.sh index 6b70a59b34..92aeb6c128 100755 --- a/flutter_ci_script_beta.sh +++ b/flutter_ci_script_beta.sh @@ -10,6 +10,7 @@ declare -a CODELABS=( "add_flutter_to_android_app" "cookbook" "cupertino_store" + "dartpad_codelabs" "firebase-get-to-know-flutter" "friendly_chat" "github-graphql-client" diff --git a/flutter_ci_script_shared.sh b/flutter_ci_script_shared.sh index 282c7c1672..6c4e63a2b6 100755 --- a/flutter_ci_script_shared.sh +++ b/flutter_ci_script_shared.sh @@ -44,18 +44,4 @@ function ci_codelabs () { done done - declare -a WORKSHOP_STEP_PATHS=($( - find dartpad_codelabs -name snippet.dart -exec dirname {} \; - )) - - for WORKSHOP_STEP_PATH in "${WORKSHOP_STEP_PATHS[@]}"; do - echo "== TESTING $WORKSHOP_STEP_PATH" - ( - cd "$WORKSHOP_STEP_PATH" - if [[ -r solution.dart ]]; then DART_FILE=solution.dart; else DART_FILE=snippet.dart; fi - set -x - dart format --output none --set-exit-if-changed $DART_FILE - ) - done - } diff --git a/flutter_ci_script_stable.sh b/flutter_ci_script_stable.sh index 07d658fe8a..77bcade6ff 100755 --- a/flutter_ci_script_stable.sh +++ b/flutter_ci_script_stable.sh @@ -10,6 +10,7 @@ declare -a CODELABS=( "add_flutter_to_android_app" "cookbook" "cupertino_store" + "dartpad_codelabs" "firebase-get-to-know-flutter" "friendly_chat" "github-graphql-client"