Build a Flutter Profile Card from a JSON Schema
Deconstruct how to compose Container, Row, Column, Text, and Icon widgets into an adaptive profile card with full standalone Dart code generation.
1. The Core Challenge & Problem
2. Architectural Principles & Resolution
3. Complete Tested Flutter Code
main.dart (Flutter 3.x+ ready)import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Color(0xFFF1F5F9),
body: Center(
child: ProfileCardExample(),
),
),
));
}
class ProfileCardExample extends StatelessWidget {
const ProfileCardExample({super.key});
@override
Widget build(BuildContext context) {
return Container(
width: 320,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: const [
BoxShadow(
color: Color(0x1A000000),
blurRadius: 12,
offset: Offset(0, 4),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Avatar circle
Container(
width: 72,
height: 72,
decoration: BoxDecoration(
color: const Color(0xFFEFF6FF),
borderRadius: BorderRadius.circular(36),
),
child: const Center(
child: Icon(Icons.person, size: 40, color: Color(0xFF2563EB)),
),
),
const SizedBox(height: 12),
// User Name
const Text(
'Alex Mercer',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF0F172A),
),
),
const SizedBox(height: 4),
// Role subtitle
const Text(
'Principal Mobile Engineer',
style: TextStyle(
fontSize: 13,
color: Color(0xFF64748B),
),
),
const SizedBox(height: 16),
// Action button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Connected with Alex Mercer!')),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF2563EB),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: const Text('Connect'),
),
),
],
),
);
}
} 4. Expected Visual & Behavioral Result
5. Common Pitfalls & Traps
Pitfall #1: Using unbounded height inside Column without mainAxisSize: MainAxisSize.min
Remedy: Columns expand vertically to fill parent constraints by default. In card widgets, always set mainAxisSize to MainAxisSize.min unless wrapped in a fixed-height container.
Pitfall #2: Applying double hex opacity strings without ARGB ordering (e.g. #2563EB80 vs Color(0x802563EB))
Remedy: Flutter Color expects 32-bit integer formatted as 0xAARRGGBB. Always place the alpha channel in the first byte position.
Pitfall #3: Deeply nesting multiple Center or Padding widgets when Container can specify both
Remedy: Utilize Container(padding: ..., alignment: ...) to consolidate layout hierarchy and reduce widget tree depth.