💄 Optimize news rendering
This commit is contained in:
parent
65fe06de22
commit
3a10e9280c
@ -185,7 +185,7 @@ PODS:
|
||||
- in_app_review (2.0.0):
|
||||
- Flutter
|
||||
- Kingfisher (8.2.0)
|
||||
- livekit_client (2.4.0):
|
||||
- livekit_client (2.4.1):
|
||||
- Flutter
|
||||
- flutter_webrtc
|
||||
- WebRTC-SDK (= 125.6422.06)
|
||||
@ -444,7 +444,7 @@ SPEC CHECKSUMS:
|
||||
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
|
||||
in_app_review: a31b5257259646ea78e0e35fc914979b0031d011
|
||||
Kingfisher: 323e5c4ec7983aaace12af655a7b51a7f88a599d
|
||||
livekit_client: 9819ebc8be8ef00ed0fae7d806bf8938ec689573
|
||||
livekit_client: 170022ce5f7c8c70d7f862ac9c17e11508ad5fbc
|
||||
media_kit_libs_ios_video: a5fe24bc7875ccd6378a0978c13185e1344651c1
|
||||
media_kit_native_event_loop: e6b2ab20cf0746eb1c33be961fcf79667304fa2a
|
||||
media_kit_video: 5da63f157170e5bf303bf85453b7ef6971218a2e
|
||||
|
@ -1,15 +1,15 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:html/dom.dart' as dom;
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:html2md/html2md.dart' as html2md;
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:relative_time/relative_time.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/types/news.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/html.dart';
|
||||
import 'package:surface/widgets/markdown_content.dart';
|
||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
@ -25,14 +25,12 @@ class NewsDetailScreen extends StatefulWidget {
|
||||
|
||||
class _NewsDetailScreenState extends State<NewsDetailScreen> {
|
||||
SnNewsArticle? _article;
|
||||
dom.Document? _articleFragment;
|
||||
|
||||
Future<void> _fetchArticle() async {
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final resp = await sn.client.get('/cgi/re/news/${widget.hash}');
|
||||
_article = SnNewsArticle.fromJson(resp.data);
|
||||
_articleFragment = parse(_article!.content);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err).then((_) {
|
||||
@ -76,7 +74,7 @@ class _NewsDetailScreenState extends State<NewsDetailScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_articleFragment != null && _isReadingFromReader)
|
||||
if (_article != null && _isReadingFromReader)
|
||||
Expanded(
|
||||
child: Container(
|
||||
constraints: BoxConstraints(maxWidth: 640),
|
||||
@ -118,8 +116,10 @@ class _NewsDetailScreenState extends State<NewsDetailScreen> {
|
||||
.textStyle(Theme.of(context).textTheme.bodySmall!)
|
||||
.opacity(0.75),
|
||||
const Divider(),
|
||||
...parseHtmlToWidgets(
|
||||
context, _articleFragment!.children),
|
||||
MarkdownTextContent(
|
||||
textScaler: TextScaler.linear(1.2),
|
||||
content: html2md.convert(_article!.content),
|
||||
),
|
||||
const Divider(),
|
||||
InkWell(
|
||||
child: Row(
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:dismissible_page/dismissible_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/flutter_highlight.dart';
|
||||
@ -207,10 +209,14 @@ class MarkdownTextContent extends StatelessWidget {
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
width ??= math.min(MediaQuery.of(context).size.width, 640);
|
||||
height ??= width;
|
||||
return UniversalImage(
|
||||
url,
|
||||
width: width,
|
||||
height: height,
|
||||
cacheHeight: height,
|
||||
cacheWidth: width,
|
||||
fit: fit,
|
||||
);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user