Skip to content

Commit 8e5f037

Browse files
committed
fix: responsive FittedBox as text grows too big
- Remove FittedBox when the screen width is >= 600px because the text become too big.
1 parent 0c1bb1b commit 8e5f037

File tree

2 files changed

+73
-36
lines changed

2 files changed

+73
-36
lines changed

client/lib/screens/detail_screen.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DetailScreen extends StatelessWidget {
5050
padding: const EdgeInsets.all(10).copyWith(bottom: 0),
5151
child: ListView(
5252
children: [
53-
FittedBox(child: HeaderWidget(video: args.video)),
53+
HeaderWidget(video: args.video),
5454
const SizedBox(height: 15),
5555
FutureBuilder<Detail>(
5656
future:

client/lib/widgets/detail/header.dart

+72-35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:fixnum/fixnum.dart';
12
import 'package:flutter/material.dart';
23
import 'package:intl/intl.dart';
34
import 'package:pr12er/protos/pkg/pr12er/messages.pb.dart';
@@ -9,52 +10,88 @@ class HeaderWidget extends StatelessWidget {
910

1011
@override
1112
Widget build(BuildContext context) {
12-
return Container(
13-
margin: const EdgeInsets.only(top: 10),
14-
child: Row(
15-
mainAxisAlignment: MainAxisAlignment.center,
16-
children: [
17-
...getPresenterWidgets(context),
18-
const SizedBox(width: 25),
19-
...getViewNumbersWidgets(),
20-
const SizedBox(width: 25),
21-
...getDateWidgets(),
22-
],
23-
),
13+
if (MediaQuery.of(context).size.width > 600) {
14+
return _HeaderInternal(video: video);
15+
}
16+
return FittedBox(
17+
child: _HeaderInternal(video: video),
2418
);
2519
}
20+
}
21+
22+
class _HeaderInternal extends StatelessWidget {
23+
const _HeaderInternal({
24+
Key? key,
25+
required this.video,
26+
}) : super(key: key);
27+
28+
final Video video;
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return Row(
33+
mainAxisAlignment: MainAxisAlignment.center,
34+
children: [
35+
Text(video.presenter, style: Theme.of(context).textTheme.subtitle1),
36+
37+
const SizedBox(width: 25),
38+
39+
// Views and likes icons
40+
_ViewsAndLikes(
41+
numberOfViews: video.numberOfViews,
42+
numberOfLike: video.numberOfLike,
43+
),
44+
45+
const SizedBox(width: 25),
46+
47+
// Date Widgets
48+
_Dates(date: video.publishedDate.toDateTime()),
49+
],
50+
);
51+
}
52+
}
53+
54+
class _Dates extends StatelessWidget {
55+
final DateTime date;
2656

27-
Widget getLikeIcon() {
28-
return const Icon(Icons.thumb_up_alt_outlined);
57+
const _Dates({Key? key, required this.date}) : super(key: key);
58+
59+
@override
60+
Widget build(BuildContext context) {
61+
return Row(
62+
children: [
63+
const Icon(Icons.today),
64+
const SizedBox(width: 8),
65+
Text(DateFormat.yMd().format(date),
66+
style: const TextStyle(fontSize: 18))
67+
],
68+
);
2969
}
70+
}
71+
72+
class _ViewsAndLikes extends StatelessWidget {
73+
final Int64 numberOfViews;
74+
final Int64 numberOfLike;
3075

31-
List<Widget> getViewNumbersWidgets() {
32-
return [
76+
const _ViewsAndLikes({
77+
Key? key,
78+
required this.numberOfViews,
79+
required this.numberOfLike,
80+
}) : super(key: key);
81+
82+
@override
83+
Widget build(BuildContext context) {
84+
return Row(children: [
3385
const SizedBox(width: 8),
3486
const Icon(Icons.remove_red_eye),
3587
const SizedBox(width: 8),
36-
Text(NumberFormat.compact().format(video.numberOfViews),
88+
Text(NumberFormat.compact().format(numberOfViews),
3789
style: const TextStyle(fontSize: 18)),
3890
const SizedBox(width: 15),
39-
getLikeIcon(),
40-
const SizedBox(width: 8),
41-
Text(NumberFormat.compact().format(video.numberOfLike),
42-
style: const TextStyle(fontSize: 18)),
43-
];
44-
}
45-
46-
List<Widget> getPresenterWidgets(BuildContext context) {
47-
return [
48-
Text(video.presenter, style: Theme.of(context).textTheme.subtitle1)
49-
];
50-
}
51-
52-
List<Widget> getDateWidgets() {
53-
return [
54-
const Icon(Icons.today),
91+
const Icon(Icons.thumb_up_alt_outlined),
5592
const SizedBox(width: 8),
56-
Text(DateFormat.yMd().format(video.publishedDate.toDateTime()),
93+
Text(NumberFormat.compact().format(numberOfLike),
5794
style: const TextStyle(fontSize: 18))
58-
];
95+
]);
5996
}
6097
}

0 commit comments

Comments
 (0)