Skip to content

Instantly share code, notes, and snippets.

@phongkien
Last active July 15, 2021 03:10
Show Gist options
  • Save phongkien/24fefdc50ab23fd320a3c57dbf843395 to your computer and use it in GitHub Desktop.
Save phongkien/24fefdc50ab23fd320a3c57dbf843395 to your computer and use it in GitHub Desktop.
card list view
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 2,
itemBuilder: (context, index) {
return buildCard();
},
);
}
Widget buildCard() {
double accentWidth = 8.0;
Color accentColor = Colors.green;
final child = Text(
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.',
style: TextStyle(color: Colors.black));
return Padding(
padding: EdgeInsets.symmetric(horizontal: 4.0),
child: Card(
elevation: 2,
shadowColor: Colors.black45,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(accentWidth),
),
),
child:
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
//this won't draw as there is no fixed height
Container(
width: accentWidth,
decoration: BoxDecoration(
color: accentColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(accentWidth),
bottomLeft: Radius.circular(accentWidth),
),
),
),
Expanded(
child: child,
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment