Last active
September 3, 2021 00:13
-
-
Save imaNNeo/561acbe8a5a01d3ca6bdd98228764aa5 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 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData( | |
brightness: Brightness.light | |
), | |
debugShowCheckedModeBanner: false, | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
// appBar: AppBar( | |
// title: Text("flutter4fun.com"), | |
// ), | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: JuiceWidget(), | |
), | |
), | |
); | |
} | |
} | |
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 JuiceWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final textStyle = TextStyle( | |
color: Colors.white, | |
fontSize: 16, | |
fontWeight: FontWeight.w600, | |
); | |
return AspectRatio( | |
aspectRatio: 1.25, | |
child: LayoutBuilder( | |
builder: (context, constraints) { | |
final topPadding = constraints.maxHeight * 0.2; | |
final leftPadding = constraints.maxWidth * 0.1; | |
final imageWidth = constraints.maxWidth * 0.35; | |
return Stack( | |
children: [ | |
Container( | |
margin: EdgeInsets.only(top: topPadding), | |
decoration: BoxDecoration(color: Color(0xFFDC691F), borderRadius: BorderRadius.circular(24)), | |
), | |
Row( | |
children: [ | |
Expanded( | |
child: Padding( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
mainAxisSize: MainAxisSize.max, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
'Besom Orange Juice', | |
style: textStyle.copyWith(fontSize: 20), | |
), | |
RichText( | |
text: TextSpan( | |
children: [ | |
TextSpan( | |
text: '\$', | |
style: textStyle.copyWith(fontSize: 16), | |
), | |
TextSpan( | |
text: '25.99', | |
style: textStyle.copyWith( | |
fontSize: 30, | |
fontWeight: FontWeight.w800, | |
), | |
), | |
], | |
), | |
), | |
SizedBox( | |
height: 32, | |
width: 80, | |
child: MyButton( | |
text: 'Buy Now', | |
textColor: Color(0xFFDC691F), | |
), | |
), | |
], | |
), | |
padding: EdgeInsets.only( | |
top: topPadding, | |
left: leftPadding, | |
), | |
), | |
), | |
SizedBox( | |
width: imageWidth, | |
child: Image.network( | |
"https://flutter4fun.com/wp-content/uploads/2021/09/juice2.png", | |
), | |
) | |
], | |
) | |
], | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://flutter4fun.com/ui-challenge-6