Simple Profile Page
Loading preview
Starting the Flutter app
A Flutter profile page with an avatar, stats, and follow and message buttons.
import 'dart:math';
import 'package:flutter/material.dart';
class ProfilePage1 extends StatefulWidget {
const ProfilePage1({super.key});
@override
State<ProfilePage1> createState() => _ProfilePage1State();
}
class _ProfilePage1State extends State<ProfilePage1> {
var _following = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: max(constraints.maxHeight * 2 / 5, 200),
child: const _TopPortion(),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(
"Richie Lorie",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium
?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Wrap(
alignment: WrapAlignment.center,
spacing: 16,
runSpacing: 12,
children: [
FloatingActionButton.extended(
onPressed: () =>
setState(() => _following = !_following),
heroTag: 'follow',
elevation: 0,
label: Text(_following ? "Following" : "Follow"),
icon: Icon(
_following ? Icons.check : Icons.person_add_alt_1,
),
),
FloatingActionButton.extended(
onPressed: () => _showDemo(context, 'Message (demo)'),
heroTag: 'message',
elevation: 0,
backgroundColor: Colors.red,
label: const Text("Message"),
icon: const Icon(Icons.message_rounded),
),
],
),
const SizedBox(height: 16),
const _ProfileInfoRow(),
],
),
),
],
),
),
),
);
}
}
class _ProfileInfoRow extends StatelessWidget {
const _ProfileInfoRow();
final List<ProfileInfoItem> _items = const [
ProfileInfoItem("Posts", 900),
ProfileInfoItem("Followers", 120),
ProfileInfoItem("Following", 200),
];
@override
Widget build(BuildContext context) {
return Container(
constraints: const BoxConstraints(maxWidth: 400, minHeight: 80),
child: IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: _items
.map(
(item) => Expanded(
child: Row(
children: [
if (_items.indexOf(item) != 0) const VerticalDivider(),
Expanded(child: _singleItem(context, item)),
],
),
),
)
.toList(),
),
),
);
}
Widget _singleItem(BuildContext context, ProfileInfoItem item) => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
item.value.toString(),
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(item.title, style: Theme.of(context).textTheme.bodySmall),
),
],
);
}
class ProfileInfoItem {
final String title;
final int value;
const ProfileInfoItem(this.title, this.value);
}
class _TopPortion extends StatelessWidget {
const _TopPortion();
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Stack(
fit: StackFit.expand,
children: [
Container(
margin: const EdgeInsets.only(bottom: 50),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [Color(0xff0043ba), Color(0xff006df1)],
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: 150,
height: 150,
child: Stack(
fit: StackFit.expand,
children: [
CircleAvatar(
backgroundColor: scheme.primaryContainer,
child: Icon(
Icons.person,
size: 90,
color: scheme.onPrimaryContainer,
),
),
Positioned(
bottom: 0,
right: 0,
child: CircleAvatar(
radius: 20,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
child: Container(
margin: const EdgeInsets.all(8.0),
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
),
),
],
),
),
),
],
);
}
}
void _showDemo(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
A LayoutBuilder gives _TopPortion two fifths of the height, at least 200px, and everything scrolls in a SingleChildScrollView. _TopPortion stacks a gradient header with an avatar straddling its lower edge, plus a green status dot. The avatar is a local Icons.person placeholder, so the demo needs no network. _ProfileInfoRow lays out ProfileInfoItem stats, Follow toggles _following, and Message shows a demo SnackBar.
Adapting it
- Pass a user model into
ProfilePage1and hand its counts to_ProfileInfoRow. - Set the
CircleAvatar’sbackgroundImageto your avatar, keeping the icon as a fallback. - Send
_followingto your API, and open your chat flow from themessagebutton.