Learn how to create a user profile page using Flutter, combining layout elements like rows, columns, and containers to display user information creatively.
Welcome to an exciting part of your Flutter journey where you’ll learn to build a user profile page! A profile page is like a personal card that shows information about a user, such as their name, picture, and hobbies. It’s a great way to apply your knowledge of layout, containers, rows, and columns. Let’s dive in and create a simple yet stylish profile page!
A profile page is a common feature in many apps, from social media to games. It provides a snapshot of a user’s identity and interests. Here’s what we’ll include in our profile page:
Before we start coding, let’s review some key concepts:
Image
widget to display a user’s photo. This can be a fun way to personalize the page.Text
widgets will help us show details like the user’s name, age, and interests.Row
, Column
, and Container
widgets, we can create an organized and visually appealing profile layout.Let’s create our profile page step by step. Below is a complete code example to guide you through the process:
import 'package:flutter/material.dart';
void main() {
runApp(ProfilePageApp());
}
class ProfilePageApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('User Profile'),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/images/profile.jpg'),
),
SizedBox(height: 20),
Text(
'Alex Johnson',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'Age: 12',
style: TextStyle(fontSize: 18),
),
SizedBox(height: 10),
Text(
'Hobbies: Painting, Reading, Gaming',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.center,
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {},
child: Text('Edit Profile'),
),
ElevatedButton(
onPressed: () {},
child: Text('View Activities'),
),
],
),
],
),
),
),
);
}
}
Note: Make sure to add the profile image (assets/images/profile.jpg
) to your project’s assets folder.
radius
property controls the size of the circle.style
property allows us to customize the font size and weight.Column
widget stacks elements vertically, while the Row
widget arranges them horizontally.onPressed
property.To better understand the structure of our profile page, let’s use a Mermaid.js diagram:
flowchart TB A[Column] --> B[Profile Picture] A --> C[User Name] A --> D[Age] A --> E[Hobbies] A --> F[Buttons Row] F --> G[Edit Profile Button] F --> H[View Activities Button]
This diagram shows how each element is organized within the Column
and Row
widgets, creating a neat and structured layout.
Now it’s your turn! Customize your profile page by:
Remember, your profile page is a reflection of you! Be creative and have fun with it. Once you’re happy with your design, share your profile page with friends or family members. You can even add more personal touches and features as you become more comfortable with layout techniques.
By building this profile page, you’ve taken another step towards mastering Flutter and creating interactive apps. Keep exploring and pushing the boundaries of your creativity!