Skip to content

Commit

Permalink
оптимизация отрисовки, изменение верстки комментов
Browse files Browse the repository at this point in the history
фикс ошибки при получении комментариев, когда пользователь забанен
  • Loading branch information
iska9der committed Sep 8, 2022
1 parent d919fe1 commit b95f49b
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 257 deletions.
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "flutter",
"command": "flutter",
"args": [
"build",
"apk",
"--release",
"--split-per-abi"
],
"group": "build",
"problemMatcher": [],
"label": "flutter: build release apk [split]",
"detail": ""
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Habra mobile client on Flutter

*apk:*
```
flutter build apk --release --split-per-abi
flutter build apk --release --split-per-abi
```

---
Expand Down
27 changes: 16 additions & 11 deletions lib/feature/article/page/article_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../component/di/dependencies.dart';
import '../../../config/constants.dart';
import '../../../widget/html_view_widget.dart';
import '../../../widget/progress_indicator.dart';
import '../../settings/widget/article_config_widget.dart';
import '../cubit/article_cubit.dart';
import '../service/article_service.dart';
import '../widget/article_card_widget.dart';
import '../widget/article_hub_widget.dart';
import '../widget/article_info_widget.dart';
import '../widget/article_statistics_widget.dart';

const double hPadding = 12.0;
Expand Down Expand Up @@ -130,13 +131,15 @@ class _ArticleDetailPageViewState extends State<ArticleDetailPageView> {
onPressed: () => showModalBottomSheet(
context: context,
builder: (context) {
return Container(
height: 240,
padding: const EdgeInsets.symmetric(
return const Padding(
padding: EdgeInsets.symmetric(
horizontal: kScreenHPadding,
vertical: kScreenHPadding * 3,
),
child: const ArticleConfigWidget(),
child: SizedBox(
height: 240,
child: ArticleConfigWidget(),
),
);
},
),
Expand Down Expand Up @@ -209,13 +212,15 @@ class _FloatingStatistics extends StatelessWidget {
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOutCubicEmphasized,
offset: isVisible ? const Offset(0, 0) : const Offset(0, 10),
child: Container(
height: 36,
child: ColoredBox(
color: Theme.of(context).colorScheme.surface.withOpacity(.95),
child: ArticleStatisticsWidget(
articleId: state.id,
statistics: stats,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
child: SizedBox(
height: 36,
child: ArticleStatisticsWidget(
articleId: state.id,
statistics: stats,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/feature/article/page/article_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class ArticleListPageView extends StatelessWidget {
child: Scrollbar(
controller: controller,
child: CustomScrollView(
cacheExtent: 1000,
controller: controller,
cacheExtent: 5000,
slivers: [
BlocBuilder<ArticleListCubit, ArticleListState>(
builder: (context, state) => SliverAppBar(
Expand Down
72 changes: 35 additions & 37 deletions lib/feature/article/widget/article_card_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:intl/intl.dart';

import '../../../common/model/render_type.dart';
import '../../../config/constants.dart';
import '../../../widget/card_widget.dart';
import '../../../widget/html_view_widget.dart';
import '../../../widget/network_image_widget.dart';
import '../../settings/cubit/settings_cubit.dart';
import '../model/article_model.dart';
import '../page/article_detail_page.dart';
import 'article_author_widget.dart';
import 'article_hub_widget.dart';
import 'article_info_widget.dart';
import 'article_statistics_widget.dart';

class ArticleCardWidget extends StatelessWidget {
Expand All @@ -32,11 +30,13 @@ class ArticleCardWidget extends StatelessWidget {
padding: const EdgeInsets.all(kCardPadding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
ArticleInfoWidget(article),
ArticleHubsWidget(hubs: article.hubs),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
if (article.leadData.image.isNotEmpty)
BlocBuilder<SettingsCubit, SettingsState>(
Expand Down Expand Up @@ -72,22 +72,40 @@ class ArticleCardWidget extends StatelessWidget {
c.feedConfig.isDescriptionVisible ||
p.feedConfig.isImageVisible != c.feedConfig.isImageVisible,
builder: (context, state) {
if (!state.feedConfig.isDescriptionVisible) return Wrap();
if (!state.feedConfig.isDescriptionVisible) {
return const SizedBox();
}

return HtmlView(
textHtml: article.leadData.textHtml,
renderMode: RenderMode.column,
customWidgetBuilder: !state.feedConfig.isImageVisible
? (element) {
if (element.localName == 'img') {
if (!state.feedConfig.isImageVisible) {
return Wrap();
}
}
return HtmlWidget(
article.leadData.textHtml,
rebuildTriggers: RebuildTriggers([
state.feedConfig,
]),
customWidgetBuilder: (element) {
if (element.localName == 'img') {
if (!state.feedConfig.isImageVisible) {
return const SizedBox();
}

return null;
}
: null,
String imgSrc = element.attributes['data-src'] ??
element.attributes['src'] ??
'';

if (imgSrc.isEmpty) {
return null;
}

return Align(
child: NetworkImageWidget(
imageUrl: imgSrc,
height: kImageHeightDefault,
isTapable: true,
),
);
}

return null;
},
);
},
),
Expand All @@ -104,26 +122,6 @@ class ArticleCardWidget extends StatelessWidget {
}
}

class ArticleInfoWidget extends StatelessWidget {
const ArticleInfoWidget(this.article, {Key? key}) : super(key: key);

final ArticleModel article;

@override
Widget build(BuildContext context) {
return Row(
children: [
ArticleAuthorWidget(article.author),
const SizedBox(width: 4),
Text(
DateFormat.yMMMMd().add_jm().format(article.publishedAt),
style: Theme.of(context).textTheme.caption,
),
],
);
}
}

class _ArticleTitleWidget extends StatelessWidget {
const _ArticleTitleWidget({
Key? key,
Expand Down
25 changes: 25 additions & 0 deletions lib/feature/article/widget/article_info_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import '../model/article_model.dart';
import 'article_author_widget.dart';

class ArticleInfoWidget extends StatelessWidget {
const ArticleInfoWidget(this.article, {Key? key}) : super(key: key);

final ArticleModel article;

@override
Widget build(BuildContext context) {
return Row(
children: [
ArticleAuthorWidget(article.author),
const SizedBox(width: 4),
Text(
DateFormat.yMMMMd().add_jm().format(article.publishedAt),
style: Theme.of(context).textTheme.caption,
),
],
);
}
}
4 changes: 3 additions & 1 deletion lib/feature/comment/model/comment_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class CommentModel extends Equatable {
factory CommentModel.fromMap(Map<String, dynamic> map) {
return CommentModel(
id: map['id'],
author: ArticleAuthorModel.fromMap(map['author']),
author: map['author'] != null && map['author'].isNotEmpty
? ArticleAuthorModel.fromMap(map['author'])
: ArticleAuthorModel.empty,
isPostAuthor: map['isPostAuthor'] as bool,
isAuthor: map['isAuthor'] as bool,
isFavorite: map['isFavorite'] as bool,
Expand Down
87 changes: 42 additions & 45 deletions lib/feature/comment/page/comment_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class CommentListView extends StatelessWidget {
}

return ListView.separated(
padding: const EdgeInsets.symmetric(
horizontal: kScreenHPadding,
),
itemCount: comments.length,
separatorBuilder: (context, index) => const SizedBox(height: 24),
itemBuilder: (context, index) {
Expand All @@ -86,7 +83,7 @@ class CommentListView extends StatelessWidget {
padding: EdgeInsets.only(
bottom: index + 1 == comments.length ? 24 : 0,
),
child: _buildTree(comment),
child: CommentTreeWidget(comment),
);
},
);
Expand All @@ -95,17 +92,25 @@ class CommentListView extends StatelessWidget {
),
);
}
}

/// Рекурсивная функция для отрисовки дерева комментариев
_buildTree(CommentModel comment) {
/// Рекурсивный виджет для отрисовки дерева комментариев
class CommentTreeWidget extends StatelessWidget {
const CommentTreeWidget(this.comment, {Key? key}) : super(key: key);

final CommentModel comment;

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
CommentWidget(comment),
for (var child in comment.children)
Padding(
padding: const EdgeInsets.only(top: 4),
child: _buildTree(child),
padding: EdgeInsets.only(left: 2.0 * child.level, top: 4),
child: CommentTreeWidget(child),
)
],
);
Expand All @@ -123,47 +128,39 @@ class CommentWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Строка автора
Row(
children: [
/// Вложенность
for (var i = 0; i <= comment.level; i++)
Padding(
padding: const EdgeInsets.only(right: 4),
child: Stack(
alignment: Alignment.center,
children: [
Icon(
i != comment.level
? Icons.circle_rounded
: Icons.circle_outlined,
size: i != comment.level ? 4 : 6,
),
],
),
),

/// Автор
Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(kBorderRadiusDefault),
color: comment.isPostAuthor
? Colors.yellowAccent.withOpacity(.12)
: null,
),
child: ArticleAuthorWidget(comment.author),
ClipRRect(
clipBehavior: Clip.hardEdge,
borderRadius: BorderRadius.circular(kBorderRadiusDefault),
child: DecoratedBox(
decoration: BoxDecoration(
color: comment.isPostAuthor
? Colors.yellowAccent.withOpacity(.12)
: Theme.of(context).colorScheme.surface,
),
Expanded(child: Wrap()),

/// Очки
StatTextWidget(
type: StatType.score,
value: comment.score,
style: Theme.of(context).textTheme.bodySmall,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: [
/// Автор
ArticleAuthorWidget(comment.author),

/// Заполняем пространство между виджетами
Expanded(child: Wrap()),

/// Очки
StatTextWidget(
type: StatType.score,
value: comment.score,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
],
),
),

const SizedBox(height: 6),

/// Дата коммента
Text(
DateFormat.yMd().add_jm().format(comment.publishedAt),
Expand Down
6 changes: 6 additions & 0 deletions lib/feature/scroll/cubit/scroll_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class ScrollCubit extends Cubit<ScrollState> {
final Duration duration;
final Curve curve;

@override
Future<void> close() {
state.controller.dispose();
return super.close();
}

void setUpEdgeListeners() {
emit(state.copyWith(isTopEdge: true));

Expand Down
Loading

0 comments on commit b95f49b

Please sign in to comment.