Skip to content

Commit ed23b5e

Browse files
committed
Responsive header: desktop left-justified, mobile avatar + username
1 parent 5c0bdcf commit ed23b5e

1 file changed

Lines changed: 54 additions & 8 deletions

File tree

lib/main.dart

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class HomePage extends StatelessWidget {
2222

2323
@override
2424
Widget build(BuildContext context) {
25+
final isMobile = MediaQuery.of(context).size.width < 600;
26+
2527
return Scaffold(
2628
body: SingleChildScrollView(
2729
child: Column(
@@ -30,14 +32,9 @@ class HomePage extends StatelessWidget {
3032
width: double.infinity,
3133
height: MediaQuery.of(context).size.height,
3234
color: const Color(0xFF3A3A3A),
33-
padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 26),
34-
alignment: Alignment.centerLeft,
35-
child: const CircleAvatar(
36-
radius: 76,
37-
backgroundImage: NetworkImage(
38-
'https://avatars.githubusercontent.com/will-ch-h',
39-
),
40-
),
35+
padding: const EdgeInsets.symmetric(horizontal: 46, vertical: 46),
36+
alignment: isMobile ? Alignment.topLeft : Alignment.centerLeft,
37+
child: isMobile ? const _MobileHeader() : const _DesktopHeader(),
4138
),
4239
Container(
4340
width: double.infinity,
@@ -50,3 +47,52 @@ class HomePage extends StatelessWidget {
5047
);
5148
}
5249
}
50+
51+
class _DesktopHeader extends StatelessWidget {
52+
const _DesktopHeader();
53+
54+
@override
55+
Widget build(BuildContext context) {
56+
return const CircleAvatar(
57+
radius: 96,
58+
backgroundImage: NetworkImage(
59+
'https://avatars.githubusercontent.com/will-ch-h',
60+
),
61+
);
62+
}
63+
}
64+
65+
class _MobileHeader extends StatelessWidget {
66+
const _MobileHeader();
67+
68+
@override
69+
Widget build(BuildContext context) {
70+
return Column(
71+
crossAxisAlignment: CrossAxisAlignment.start,
72+
children: [
73+
Row(
74+
crossAxisAlignment: CrossAxisAlignment.center,
75+
children: [
76+
const CircleAvatar(
77+
radius: 40,
78+
backgroundImage: NetworkImage(
79+
'https://avatars.githubusercontent.com/will-ch-h',
80+
),
81+
),
82+
const SizedBox(width: 16),
83+
const Text(
84+
'will-ch-h',
85+
style: TextStyle(
86+
color: Colors.white,
87+
fontSize: 22,
88+
fontWeight: FontWeight.bold,
89+
),
90+
),
91+
],
92+
),
93+
const SizedBox(height: 24),
94+
// information goes here
95+
],
96+
);
97+
}
98+
}

0 commit comments

Comments
 (0)