Flutter Card Widget Tutorial: A Comprehensive Guide

The Card Widget in Flutter is a versatile and visually appealing way to present content. Whether you want to display text, images, or interactive elements, the card widget provides a customizable container with features like shadows, borders, and rounded corners. In this tutorial, we explore various use cases and implementations of the card widget to enhance your app’s user interface.

Flutter Card Widget Tutorial

1. Basic Card

A simple card can act as a clean container for text or any content. Here’s how you can create one:

Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("This is a basic card."),
),
)

Output:

A minimal card with a text element.

2. Card with Elevation

Add depth and a 3D effect to your card by using the elevation property:

Card(
elevation: 10,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with elevation."),
),
)

Why Use It?

Elevation helps cards stand out, especially in layered designs.

3. Rounded Corners

Give your cards a modern look by rounding the edges:

Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with rounded corners."),
),
)

4. Add Borders

Add a border with customizable width and color:

Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: Colors.blue, width: 2),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with a border."),
),
)

5. Card with an Image

Combine images with text or other widgets:

Card(
child: Column(
children: [
Image.network("https://via.placeholder.com/150"),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with an image."),
),
],
),
)

6. Card with Icon and Text

Integrate icons into your card for enhanced usability:

Card(
child: ListTile(
leading: Icon(Icons.star, color: Colors.amber),
title: Text("Card with an icon."),
subtitle: Text("This card has both icon and text."),
),
)

7. Card with Buttons

Add interactivity to your cards with action buttons:

Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: Icon(Icons.album),
title: Text("Card with buttons"),
subtitle: Text("This card has action buttons below."),
),
ButtonBar(
children: [
TextButton(
onPressed: () {},
child: Text("ACTION 1"),
),
TextButton(
onPressed: () {},
child: Text("ACTION 2"),
),
],
),
],
),
)

8. Gradient Background

Create a card with an eye-catching gradient background:

Card(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with gradient background."),
),
),
)

9. Interactive Card

Make your cards clickable with the InkWell widget:

Card(
child: InkWell(
onTap: () {
print("Card tapped!");
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Tap me!"),
),
),
)

10. Scrollable Card List

Display multiple cards in a vertically scrollable list:

ListView(
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card 1"),
),
),
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card 2"),
),
),
],
)

11. Horizontal Card

Create a horizontally scrollable card list:

SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Card(
child: Container(
width: 200,
height: 150,
color: Colors.red,
),
),
Card(
child: Container(
width: 200,
height: 150,
color: Colors.green,
),
),
],
),
)

12. Custom Shadow

Customize the card’s shadow color and spread:

Card(
elevation: 10,
shadowColor: Colors.red,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("Card with custom shadow color."),
),
)

13. Card with Stack

Layer widgets on top of each other for a creative design:

Card(
child: Stack(
children: [
Container(
height: 150,
color: Colors.blue,
),
Positioned(
bottom: 10,
left: 10,
child: Text(
"Overlay text on a card.",
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
],
),
)

Conclusion

The Card Widget in Flutter is a powerful tool for building beautiful, responsive UI designs. From simple text containers to interactive, image-laden cards, it offers endless possibilities. Experiment with these examples to find the perfect implementation for your app.

Explore Other Flutter Topics…

  1. Introduction to Flutter and Dart
  2. Why choose Flutter
  3. Installing Flutter On Your Windows Mac And Linux System
  4. Your first Flutter app
  5. Flutter project structure
  6. Building blocks of Flutter
  7. Stateful vs. Stateless Widgets Explained
  8. Flutter layout system
  9. Flutter text widget
  10. Creating Buttons in Flutter: ElevatedButton, TextButton, and IconButton
  11. Handling User Input with Flutter Forms
  12. Container class in Flutter
  13. Flutter Navigation
  14. Flutter – Pass Data One Screen To Another Screen
  15. Managing Device Orientation in Flutter
  16. Stateful widget lifecycle in Flutter
  17. Future of Flutter
  18. Flutter Themes
  19. Flutter Animations
  20. Flutter AppBar Customization
  21. ListView in Flutter
  22. Flutter GridView
  23. Flutter Expanded Widget
  24. Flutter BottomNavigation Bar
  25. Floating Action Button
  26. Drawer Widgets in Flutter
  27. Form Validation in Flutter
  28. Flutter TextField
  29. Adding AdMob ads to a Flutter app
  30. Building Flutter Web & Desktop Applications
  31. What is Async and Await in Flutter
  32. HTTP requests in Flutter
  33. Parsing JSON in Flutter
  34. Tinder-Style Swipe Cards in Flutter
  35. Flutter Tic Tac Toe Game Tutorial
  36. Flutter Login UI Tutorial
  37. Flutter Card Widget Tutorial
  38. Flutter music player app tutorial
  39. Flutter introduction screens
  40. Shared Preferences in Flutter
  41. SQLite Database in Flutter
  42. Firebase Authentication in Flutter
  43. Firebase Firestore in Flutter
  44. Push Notifications in Flutter
  45. Handling File Uploads in Flutter
  46. Responsive Design in Flutter
  47. Provider in Flutter
  48. Riverpod in Flutter
  49. Flutter BLoC Pattern Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *