Skip to content

Commit 33922ba

Browse files
committed
redesing
1 parent 3963d63 commit 33922ba

File tree

6 files changed

+97
-29
lines changed

6 files changed

+97
-29
lines changed

lib/pages/article/article.dart

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,35 +257,47 @@ class ArticleView extends StatelessWidget {
257257
Widget build(BuildContext context) {
258258
final appSettings = context.watch<AppSettings>();
259259
final textAlign = appSettings.articleTextAlign;
260+
const padding = EdgeInsets.symmetric(horizontal: 10);
260261
final listview = SingleChildScrollView(
261-
padding: const EdgeInsets.all(10).copyWith(bottom: 20),
262+
padding: const EdgeInsets.only(top: 10, bottom: 20),
262263
controller: controller,
263264
child: CenterAdaptiveConstrait(
264265
child: Column(
265266
children: [
266-
ArticleInfo(
267-
article: article,
267+
Padding(
268+
child: ArticleInfo(
269+
article: article,
270+
),
271+
padding: padding,
268272
),
269273
SizedBox(
270274
height: 30,
271275
),
272-
HtmlView(article!.parsedBody, textAlign: textAlign),
276+
HtmlView(
277+
article!.parsedBody,
278+
textAlign: textAlign,
279+
imagesWithPadding: false,
280+
padding: padding,
281+
),
273282
SizedBox(
274283
height: 20,
275284
),
276285
InkWell(
277286
child: Padding(
278-
padding: const EdgeInsets.only(left: 5, top: 5, bottom: 5),
287+
padding: const EdgeInsets.only(left: 10, top: 5, bottom: 5),
279288
child: MediumAuthorPreview(article!.author)),
280289
onTap: () =>
281290
openUser(context, article!.author.alias), // open user page
282291
),
283292
SizedBox(
284293
height: 20,
285294
),
286-
CommentsButton(
287-
onPressed: () => openCommentsPage(context, article!.id),
288-
)
295+
Padding(
296+
child: CommentsButton(
297+
onPressed: () => openCommentsPage(context, article!.id),
298+
),
299+
padding: padding,
300+
),
289301
],
290302
),
291303
),

lib/pages/comments/comments.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ class CommentView extends StatelessWidget {
114114
return Padding(
115115
padding: EdgeInsets.only(top: 5, bottom: 5),
116116
child: Column(
117-
crossAxisAlignment: CrossAxisAlignment.start,
117+
crossAxisAlignment: CrossAxisAlignment.stretch,
118118
children: [
119-
Row(
119+
Wrap(
120120
children: [
121121
InkWell(
122122
child: SmallAuthorPreview(comment.author!),
@@ -125,7 +125,8 @@ class CommentView extends StatelessWidget {
125125
Text(dateToStr(
126126
comment.timePublished!, Localizations.localeOf(context))),
127127
],
128-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
128+
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
129+
alignment: WrapAlignment.spaceBetween,
129130
),
130131
const SizedBox(
131132
height: 10,

lib/widgets/html_elements/highlight_code.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class _HighlightViewState extends State<_HighlightView> {
187187
}
188188

189189
return Container(
190+
constraints: BoxConstraints(
191+
minWidth: MediaQuery.of(context).size.width.clamp(0, 880)),
190192
color:
191193
widget.theme![_rootKey]?.backgroundColor ?? _defaultBackgroundColor,
192194
padding: widget.padding,

lib/widgets/html_view.dart

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_highlight/themes/paraiso-dark.dart';
34
import 'package:habr_app/stores/app_settings.dart';
45
import 'package:provider/provider.dart';
56
import 'package:itertools/itertools.dart';
@@ -16,31 +17,59 @@ import 'package:habr_app/utils/log.dart';
1617
class HtmlView extends StatelessWidget {
1718
final view.Node node;
1819
final TextAlign? textAlign;
20+
final bool imagesWithPadding;
21+
final EdgeInsets? padding;
1922

20-
HtmlView(this.node, {this.textAlign});
23+
HtmlView(
24+
this.node, {
25+
this.textAlign,
26+
this.imagesWithPadding = true,
27+
this.padding,
28+
});
2129

2230
@override
2331
Widget build(BuildContext context) {
2432
return Column(
2533
children: inlineTree(
2634
node,
2735
context,
28-
BuildParams(textAlign: textAlign),
36+
BuildParams(
37+
textAlign: textAlign,
38+
imagesWithPadding: imagesWithPadding,
39+
padding: padding,
40+
),
2941
).toList(),
3042
crossAxisAlignment: CrossAxisAlignment.stretch,
3143
);
3244
}
3345

34-
HtmlView.unparsed(String? html, {this.textAlign})
35-
: node = htmlAsParsedJson(html);
46+
HtmlView.unparsed(
47+
String? html, {
48+
this.textAlign,
49+
this.imagesWithPadding = false,
50+
this.padding,
51+
}) : node = htmlAsParsedJson(html);
3652
}
3753

3854
class BuildParams {
3955
final TextAlign? textAlign;
56+
final bool imagesWithPadding;
57+
final EdgeInsets? padding;
4058

41-
BuildParams({this.textAlign});
59+
BuildParams({
60+
this.textAlign,
61+
required this.imagesWithPadding,
62+
this.padding,
63+
});
4264
}
4365

66+
Widget wrapPadding(Widget child, BuildParams params) => params.padding != null
67+
? Padding(
68+
padding: params.padding!,
69+
child: child,
70+
)
71+
: child;
72+
4473
// may be null
4574
Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
4675
final type = element.type;
@@ -56,11 +85,13 @@ Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
5685
if (element is view.HeadLine) {
5786
final mode = HeadLineType.values[int.parse(element.mode.substring(1)) - 1];
5887
widget = HeadLine(text: element.text, type: mode);
88+
widget = wrapPadding(widget, params);
5989
} else if (element is view.TextParagraph) {
6090
widget = Text(
6191
element.text,
6292
textAlign: params.textAlign,
6393
);
94+
widget = wrapPadding(widget, params);
6495
} else if (element is view.Paragraph) {
6596
widget = Text.rich(
6697
TextSpan(
@@ -69,6 +100,7 @@ Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
69100
.toList()),
70101
textAlign: params.textAlign,
71102
);
103+
widget = wrapPadding(widget, params);
72104
} else if (element is view.Scrollable) {
73105
widget = SingleChildScrollView(
74106
child: buildTree(element.child, context, params),
@@ -88,6 +120,12 @@ Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
88120
distance: 5,
89121
);
90122
}
123+
if (params.imagesWithPadding) {
124+
widget = Padding(
125+
padding: params.padding!,
126+
child: widget,
127+
);
128+
}
91129
} else if (element is view.Code) {
92130
final appSettings = Provider.of<AppSettings>(context, listen: false);
93131
widget = HighlightCode(
@@ -100,28 +138,33 @@ Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
100138
);
101139
} else if (element is view.BlockQuote) {
102140
widget = BlockQuote(child: buildTree(element.child, context, params));
141+
widget = wrapPadding(widget, params);
103142
} else if (element is view.BlockList) {
104143
// TODO: ordered list
105144
widget = UnorderedList(
106145
children: element.children
107146
.map<Widget?>((li) => buildTree(li, context, params))
108147
.notNull
109148
.toList());
149+
widget = wrapPadding(widget, params);
110150
} else if (element is view.BlockColumn) {
111151
widget = WrappedContainer(
112152
children: element.children
113153
.map<Widget?>((child) => buildTree(child, context, params))
114154
.notNull
115155
.toList());
156+
widget = wrapPadding(widget, params);
116157
} else if (element is view.Details) {
117158
widget = Spoiler(
118159
title: element.title,
119160
child: buildTree(element.child, context, params),
120161
);
162+
widget = wrapPadding(widget, params);
121163
} else if (element is view.Iframe) {
122164
widget = Iframe(
123165
src: element.src,
124166
);
167+
widget = wrapPadding(widget, params);
125168
} else if (element is view.Table) {
126169
try {
127170
widget = Table(
@@ -141,6 +184,7 @@ Widget? buildTree(view.Node element, BuildContext context, BuildParams params) {
141184
} catch (err) {
142185
widget = Text("Unsupported table");
143186
}
187+
widget = wrapPadding(widget, params);
144188
} else {
145189
logInfo("Not found case for $type");
146190
}
@@ -186,7 +230,8 @@ Iterable<Widget> inlineTree(
186230
}
187231
} else if (element is view.BlockList) {
188232
for (final item in element.children) {
189-
yield UnorderedItem(child: buildTree(item, context, params)!);
233+
yield wrapPadding(
234+
UnorderedItem(child: buildTree(item, context, params)!), params);
190235
}
191236
} else {
192237
yield buildTree(element!, context, params)!;

lib/widgets/small_author_preview.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ class SmallAuthorPreview extends StatelessWidget {
1414
@override
1515
Widget build(BuildContext context) {
1616
final themeData = Theme.of(context);
17-
return Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
18-
AuthorAvatarIcon(
19-
key: ValueKey('avatar_${author.avatar.hashCode}'),
20-
avatar: author.avatar,
21-
defaultColor: AvatarColorStore().getColor(author.alias, themeData.brightness),
22-
),
23-
SizedBox(
24-
width: 5,
25-
),
26-
Text(author.alias, style: textStyle),
27-
]);
17+
return Row(
18+
crossAxisAlignment: CrossAxisAlignment.center,
19+
children: [
20+
AuthorAvatarIcon(
21+
key: ValueKey('avatar_${author.avatar.hashCode}'),
22+
avatar: author.avatar,
23+
defaultColor:
24+
AvatarColorStore().getColor(author.alias, themeData.brightness),
25+
),
26+
SizedBox(
27+
width: 5,
28+
),
29+
Text(author.alias, style: textStyle),
30+
],
31+
mainAxisSize: MainAxisSize.min,
32+
);
2833
}
2934
}

pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ dependencies:
2828
hive_flutter: ^1.1.0
2929
flutter_slidable: 0.6.0
3030
photo_view: ^0.13.0
31-
path_provider: "^2.0.2"
31+
path_provider: "^2.0.9"
3232
crypto: ">=2.1.5"
3333
provider: ^5.0.0
3434
itertools: ">=0.1.0"
3535

36+
dependency_overrides:
37+
platform: ^3.1.0
38+
3639
dev_dependencies:
3740
flutter_test:
3841
sdk: flutter

0 commit comments

Comments
 (0)