Skip to content

Instantly share code, notes, and snippets.

@imaNNeo
Last active September 3, 2021 00:13
Show Gist options
  • Save imaNNeo/94feebc38130839e0834e8c5adda98e9 to your computer and use it in GitHub Desktop.
Save imaNNeo/94feebc38130839e0834e8c5adda98e9 to your computer and use it in GitHub Desktop.
Flutter4Fun.com - UI Challenge 6
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: ListView.builder(
padding: EdgeInsets.all(20),
itemBuilder: (context, index) {
return JuiceWidget(juiceList[index]);
},
itemCount: juiceList.length,
),
),
);
}
}
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,
),
);
}
}
final juiceList = [
JuiceEntity(
name: 'Besom Yellow Juice',
image: 'https://flutter4fun.com/wp-content/uploads/2021/09/juice1.png',
price: '19.99',
color: Color(0xFFF3BE39),
),
JuiceEntity(
name: 'Besom Orange Juice',
image: 'https://flutter4fun.com/wp-content/uploads/2021/09/juice2.png',
price: '25.99',
color: Color(0xFFDC691F),
),
];
class JuiceEntity {
final String name;
final String image;
final String price;
final Color color;
JuiceEntity({
required this.name,
required this.image,
required this.price,
required this.color,
});
}
class JuiceWidget extends StatelessWidget {
final JuiceEntity juice;
const JuiceWidget(this.juice);
@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: juice.color, borderRadius: BorderRadius.circular(24)),
),
Row(
children: [
Expanded(
child: Padding(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
juice.name,
style: textStyle.copyWith(fontSize: 20),
),
RichText(
text: TextSpan(
children: [
TextSpan(
text: '\$',
style: textStyle.copyWith(fontSize: 16),
),
TextSpan(
text: juice.price,
style: textStyle.copyWith(
fontSize: 30,
fontWeight: FontWeight.w800,
),
),
],
),
),
SizedBox(
height: 32,
width: 80,
child: MyButton(
text: 'Buy Now',
textColor: juice.color,
),
),
],
),
padding: EdgeInsets.only(
top: topPadding,
left: leftPadding,
),
),
),
SizedBox(
width: imageWidth,
child: Image.network(juice.image),
)
],
)
],
);
},
),
);
}
}
@imaNNeo
Copy link
Author

imaNNeo commented Sep 2, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment