From 4938ede6f8721a94e40065dcce56c45226817f7d Mon Sep 17 00:00:00 2001 From: Subhanshu Sahani <72247207+Sahani18@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:34:33 +0530 Subject: [PATCH] Update main.dart new keyword is optional in dart so try to omit it. Use fat arrow to write main method,code should be optimized. --- lib/full_version/main.dart | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/full_version/main.dart b/lib/full_version/main.dart index 61e2998..0c65839 100644 --- a/lib/full_version/main.dart +++ b/lib/full_version/main.dart @@ -6,16 +6,14 @@ import 'package:flutter/material.dart'; import 'places.dart' as places; -void main() { - runApp(new NomNomApp()); -} +void main() => runApp(NomNomApp()); class NomNomApp extends StatelessWidget { @override Widget build(BuildContext context) { - return new MaterialApp( + return MaterialApp( title: 'Nom Nom', - theme: new ThemeData( + theme: ThemeData( primarySwatch: Colors.blue, ), home: new MyHomePage(title: 'Nom Nom'), @@ -48,12 +46,12 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text(widget.title), + return Scaffold( + appBar: AppBar( + title: Text(widget.title), ), - body: new ListView( - children: placeList.map((place) => new PlaceWidget(place)).toList(), + body: ListView( + children: placeList.map((place) => PlaceWidget(place)).toList(), ), ); } @@ -68,25 +66,25 @@ class PlaceWidget extends StatelessWidget { // Normalize rating to (0,1) and interpolate color from red to green var ratingColor = Color.lerp(Colors.red, Colors.green, place.rating / 5); - var listTile = new ListTile( - leading: new CircleAvatar( - child: new Text(place.rating.toString()), + var listTile = ListTile( + leading: CircleAvatar( + child: Text(place.rating.toString()), backgroundColor: ratingColor, ), - title: new Text(place.name), - subtitle: new Text(place.address ?? "unknown ..."), + title: Text(place.name), + subtitle: Text(place.address ?? "unknown ..."), isThreeLine: false, ); - return new Dismissible( - key: new Key(place.name), + return Dismissible( + key: Key(place.name), onDismissed: (dir) => dir == DismissDirection.startToEnd ? print('You favorited ${place.name}!') : print('You dismissed ${place.name} ...'), - background: new Container( + background: Container( color: Colors.green, ), - secondaryBackground: new Container(color: Colors.red), + secondaryBackground: Container(color: Colors.red), child: listTile, ); }