Skip to content

Commit

Permalink
Merge pull request #2 from j-j-gajjar/jay
Browse files Browse the repository at this point in the history
migration code with null safety
  • Loading branch information
j-j-gajjar authored Oct 1, 2021
2 parents 384ee40 + 28c565e commit 1a145ea
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 193 deletions.
50 changes: 13 additions & 37 deletions lib/DataOfList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import 'listOfData.dart';

class DataOfList extends StatelessWidget {
DataOfList({this.data});
final ListOfData data;
final ListOfData? data;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.orange,
title: Text("Cartoon"),
centerTitle: true,
elevation: 0,
),
appBar: AppBar(backgroundColor: Colors.orange, title: Text("Cartoon"), centerTitle: true, elevation: 0),
backgroundColor: Colors.orange,
body: DataBody(data: data),
);
Expand All @@ -23,42 +18,33 @@ class DataOfList extends StatelessWidget {

class DataBody extends StatelessWidget {
DataBody({this.data});
final ListOfData data;
final ListOfData? data;
@override
Widget build(BuildContext context) {
return Center(
child: Container(
width: MediaQuery.of(context).size.width * 80 / 100,
height: MediaQuery.of(context).size.height * 60 / 100,
decoration: BoxDecoration(
//color: Colors.white,
borderRadius: BorderRadius.circular(35),
),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(35)),
child: Stack(
children: [
Positioned(
bottom: 0,
child: Container(
width: MediaQuery.of(context).size.width * 80 / 100,
height: MediaQuery.of(context).size.height * 50 / 100,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(35),
),
decoration: BoxDecoration(color: Colors.green, borderRadius: BorderRadius.circular(35)),
child: Container(
margin: EdgeInsets.only(bottom: 10),
width: MediaQuery.of(context).size.width * 80 / 100,
height: MediaQuery.of(context).size.height * 50 / 100,
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(35),
),
decoration: BoxDecoration(color: Colors.white70, borderRadius: BorderRadius.circular(35)),
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Hero(tag: data.id, child: Image.asset(data.img)),
child: Hero(tag: data!.id!, child: Image.asset(data!.img!)),
),
Positioned(
bottom: 0,
Expand All @@ -67,26 +53,16 @@ class DataBody extends StatelessWidget {
children: [
Center(
child: Text(
data.name,
style: TextStyle(
color: Colors.pink,
fontSize: 70,
fontWeight: FontWeight.bold),
data!.name!,
style: TextStyle(color: Colors.pink, fontSize: 70, fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10,
),
SizedBox(height: 10),
Text(
"\$${data.prise.toString()}",
style: TextStyle(
color: Colors.red,
fontSize: 40,
fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
"\$${data!.prise.toString()}",
style: TextStyle(color: Colors.red, fontSize: 40, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
],
),
)
Expand Down
4 changes: 2 additions & 2 deletions lib/listOfData.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ListOfData {
ListOfData({this.id, this.prise, this.name, this.img});
final int id, prise;
final String name, img;
final int? id, prise;
final String? name, img;
}

List<ListOfData> listdata = [
Expand Down
68 changes: 17 additions & 51 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ void main() {
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
backgroundColor: Colors.orange,
title: Text("Cartoon"),
centerTitle: true,
elevation: 0,
),
appBar: AppBar(backgroundColor: Colors.orange, title: Text("Cartoon"), centerTitle: true, elevation: 0),
body: AppBody(),
),
);
Expand Down Expand Up @@ -59,21 +53,14 @@ class _AppBodyState extends State<AppBody> {
),
OrientationBuilder(builder: (context, orientation) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
orientation == Orientation.portrait ? 2 : 3),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: orientation == Orientation.portrait ? 2 : 3),
itemBuilder: (context, index) => Container(
child: Container(
margin:
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Container(
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
DataOfList(data: listdata[index])));
Navigator.push(context, MaterialPageRoute(builder: (context) => DataOfList(data: listdata[index])));
},
child: Stack(
children: [
Expand All @@ -83,17 +70,12 @@ class _AppBodyState extends State<AppBody> {
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 10.0, // soften the shadow
spreadRadius: 1.0, //extend the shadow
offset: Offset(
14.0, // Move to right 10 horizontally
19.0, // Move to bottom 10 Vertically
),
blurRadius: 10.0,
spreadRadius: 1.0,
offset: Offset(14.0, 19.0),
),
],
color: index.isEven
? Colors.blue
: Colors.pinkAccent,
color: index.isEven ? Colors.blue : Colors.pinkAccent,
borderRadius: BorderRadius.circular(20),
),
child: Container(
Expand All @@ -106,8 +88,7 @@ class _AppBodyState extends State<AppBody> {
child: Center(
child: Text(
"\$${listdata[index].prise.toString()}",
style: TextStyle(
color: Colors.yellow),
style: TextStyle(color: Colors.yellow),
),
),
color: Colors.red,
Expand All @@ -121,35 +102,26 @@ class _AppBodyState extends State<AppBody> {
],
),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20)),
decoration: BoxDecoration(color: Colors.white70, borderRadius: BorderRadius.circular(20)),
),
),
Positioned(
top: 0,
child: Container(
height: 120,
width: 120,
child: Hero(
tag: listdata[index].id,
child: Image.asset(listdata[index].img))),
child:
Container(height: 120, width: 120, child: Hero(tag: listdata[index].id!, child: Image.asset(listdata[index].img!))),
),
Positioned(
bottom: 0,
child: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: 15, vertical: 15),
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
child: Row(
children: [
Text(
listdata[index].name,
listdata[index].name!,
style: TextStyle(
color: index.isEven
? Colors.pinkAccent
: Colors.blue,
color: index.isEven ? Colors.pinkAccent : Colors.blue,
fontSize: 20,
fontWeight: FontWeight.bold,
),
Expand Down Expand Up @@ -182,11 +154,7 @@ class _AppBodyState extends State<AppBody> {
height: MediaQuery.of(context).size.height * 8 / 100,
child: ListView.builder(
itemBuilder: (context, index) => GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
onTap: () => setState(() => selectedIndex = index),
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
Expand All @@ -198,9 +166,7 @@ class _AppBodyState extends State<AppBody> {
child: Text(
listdata[index].name.toString(),
style: TextStyle(
fontWeight: selectedIndex == index
? FontWeight.bold
: FontWeight.normal,
fontWeight: selectedIndex == index ? FontWeight.bold : FontWeight.normal,
color: Colors.black,
fontSize: 15,
),
Expand Down
Loading

0 comments on commit 1a145ea

Please sign in to comment.