Created
September 3, 2021 17:43
-
-
Save imaNNeo/675018f14d7f8c74e5378360e72ef280 to your computer and use it in GitHub Desktop.
Flutter4Fun.com - UI Challenge 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData(brightness: Brightness.light), | |
debugShowCheckedModeBanner: false, | |
home: JuiceDetailsPage(), | |
); | |
} | |
} | |
class MyButton extends StatelessWidget { | |
final String text; | |
final Color bgColor; | |
final Color textColor; | |
MyButton({ | |
Key? key, | |
required this.text, | |
this.bgColor = Colors.white, | |
this.textColor = Colors.black, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return ElevatedButton( | |
onPressed: () {}, | |
child: Text( | |
text, | |
style: TextStyle( | |
color: textColor, | |
fontWeight: FontWeight.w700, | |
fontSize: 12, | |
), | |
), | |
style: ElevatedButton.styleFrom( | |
elevation: 0, | |
shadowColor: Colors.transparent, | |
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8))), | |
primary: bgColor, | |
), | |
); | |
} | |
} | |
class JuiceDetailsPage extends StatefulWidget { | |
@override | |
_JuiceDetailsPageState createState() => _JuiceDetailsPageState(); | |
} | |
class SimpleRatingBar extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Row( | |
children: List.generate( | |
5, | |
(index) => Icon( | |
Icons.star, | |
color: Color(0xFFFFBA00), | |
size: 18, | |
), | |
), | |
); | |
} | |
} | |
final List<String> reviewImages = [ | |
'https://flutter4fun.com/wp-content/uploads/2021/09/1.png', | |
'https://flutter4fun.com/wp-content/uploads/2021/09/2.png', | |
'https://flutter4fun.com/wp-content/uploads/2021/09/3.png', | |
'https://flutter4fun.com/wp-content/uploads/2021/09/4.png', | |
]; | |
final addImageUrl = 'https://flutter4fun.com/wp-content/uploads/2021/09/add.png'; | |
class ReviewsList extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
height: 48, | |
child: ListView.separated( | |
scrollDirection: Axis.horizontal, | |
separatorBuilder: (_, index) => SizedBox(width: 18), | |
itemBuilder: (_, index) { | |
if (index == reviewImages.length) { | |
return Image.network(addImageUrl); | |
} | |
return Image.network(reviewImages[index]); | |
}, | |
itemCount: reviewImages.length + 1, | |
), | |
); | |
} | |
} | |
class _JuiceDetailsPageState extends State<JuiceDetailsPage> { | |
var count = 0; | |
double bottomSectionHeight = 100; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: Stack( | |
children: [ | |
ListView( | |
padding: EdgeInsets.only(bottom: bottomSectionHeight), | |
children: [ | |
AspectRatio( | |
child: LayoutBuilder( | |
builder: (context, constraints) { | |
final imageHeight = constraints.maxHeight * 0.7; | |
final imageHorizontalMargin = constraints.maxWidth * 0.15; | |
final imageBottomMargin = constraints.maxHeight * 0.07; | |
return Stack( | |
children: [ | |
Container( | |
decoration: BoxDecoration( | |
color: Color(0xFFF3BE39), | |
borderRadius: BorderRadius.only( | |
bottomLeft: Radius.circular(32), | |
bottomRight: Radius.circular(32), | |
), | |
), | |
child: Align( | |
alignment: Alignment.bottomCenter, | |
child: Padding( | |
padding: EdgeInsets.only( | |
left: imageHorizontalMargin, | |
right: imageHorizontalMargin, | |
bottom: imageBottomMargin, | |
), | |
child: Image.network( | |
'https://flutter4fun.com/wp-content/uploads/2021/09/full.png', | |
height: imageHeight, | |
), | |
), | |
), | |
), | |
Transform.translate( | |
offset: Offset(0, 26), | |
child: Align( | |
alignment: Alignment.bottomCenter, | |
child: CounterWidget( | |
currentCount: count, | |
color: Color(0xFFF3BE39), | |
onIncreaseClicked: () { | |
setState(() { | |
count++; | |
}); | |
}, | |
onDecreaseClicked: () { | |
setState(() { | |
count--; | |
}); | |
}, | |
), | |
), | |
) | |
], | |
); | |
}, | |
), | |
aspectRatio: 0.86, | |
), | |
SizedBox(height: 58), | |
Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 12.0), | |
child: Column( | |
children: [ | |
Row( | |
children: [ | |
Text( | |
'Besom Orange Juice', | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w700, | |
), | |
), | |
SimpleRatingBar() | |
], | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
), | |
SizedBox(height: 16), | |
Text( | |
'Drinking Orange Juice is not only enhances health body also strengthens muscles', | |
style: TextStyle(color: Color(0xFFB0B1B4), fontSize: 16), | |
), | |
SizedBox(height: 24), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Text( | |
'Reviews', | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w700, | |
), | |
), | |
Text( | |
'See all', | |
style: TextStyle( | |
color: Color(0xFFD81C33), | |
decoration: TextDecoration.underline, | |
), | |
) | |
], | |
), | |
SizedBox(height: 16), | |
ReviewsList(), | |
], | |
), | |
) | |
], | |
), | |
Container( | |
color: Color(0xFFF3BE39), | |
padding: EdgeInsets.only(left: 24, right: 24, top: 26, bottom: 8), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
GestureDetector( | |
child: Image.network( | |
'https://flutter4fun.com/wp-content/uploads/2021/09/back.png', | |
width: 32, | |
), | |
onTap: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
Text( | |
'Besom.', | |
style: TextStyle( | |
fontSize: 26, | |
fontWeight: FontWeight.w800, | |
color: Colors.white, | |
), | |
), | |
Image.network( | |
'https://flutter4fun.com/wp-content/uploads/2021/09/shop_white.png', | |
width: 32, | |
) | |
], | |
), | |
), | |
Align( | |
alignment: Alignment.bottomCenter, | |
child: Container( | |
height: bottomSectionHeight, | |
color: Colors.white, | |
padding: EdgeInsets.symmetric(horizontal: 12), | |
child: Row( | |
children: [ | |
Expanded( | |
child: RichText( | |
text: TextSpan( | |
style: TextStyle(color: Colors.black), | |
children: [ | |
TextSpan( | |
text: '\$', | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
TextSpan( | |
text: '25.99', | |
style: TextStyle( | |
fontSize: 36, | |
fontWeight: FontWeight.w800, | |
), | |
), | |
], | |
), | |
), | |
), | |
SizedBox( | |
width: 120, | |
height: 48, | |
child: MyButton( | |
text: 'Buy Now', | |
bgColor: Color(0xFFF3BE39), | |
textColor: Colors.white, | |
), | |
) | |
], | |
), | |
), | |
) | |
], | |
), | |
); | |
} | |
} | |
class CounterWidget extends StatelessWidget { | |
final int currentCount; | |
final Color color; | |
final VoidCallback? onIncreaseClicked; | |
final VoidCallback? onDecreaseClicked; | |
final textStyle = TextStyle(color: Colors.white, fontWeight: FontWeight.w700, fontSize: 18); | |
CounterWidget({ | |
required this.currentCount, | |
required this.color, | |
this.onIncreaseClicked, | |
this.onDecreaseClicked, | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
height: 52, | |
decoration: BoxDecoration( | |
color: color, | |
borderRadius: BorderRadius.circular(18), | |
border: Border.all(color: Colors.white), | |
), | |
child: Row( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
SizedBox(width: 16), | |
GestureDetector(child: Icon(Icons.remove, color: Colors.white), onTap: onDecreaseClicked), | |
SizedBox(width: 10), | |
SizedBox( | |
width: 30, | |
child: Text( | |
currentCount.toString(), | |
style: textStyle, | |
textAlign: TextAlign.center, | |
), | |
), | |
SizedBox(width: 10), | |
GestureDetector(child: Icon(Icons.add, color: Colors.white), onTap: onIncreaseClicked), | |
SizedBox(width: 16), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment