mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: article (#757)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
196
lib/pages/article/widgets/opus_content.dart
Normal file
196
lib/pages/article/widgets/opus_content.dart
Normal file
@@ -0,0 +1,196 @@
|
||||
import 'package:PiliPlus/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart'
|
||||
show SourceModel;
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/dynamics/opus_detail/module.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
Widget opusContent({
|
||||
required BuildContext context,
|
||||
required List<OpusModule>? modules,
|
||||
Function(List<String>, int)? callback,
|
||||
required double maxWidth,
|
||||
}) {
|
||||
debugPrint('opusContent');
|
||||
|
||||
if (modules.isNullOrEmpty) {
|
||||
return const SliverToBoxAdapter();
|
||||
}
|
||||
|
||||
return SliverMainAxisGroup(
|
||||
slivers: modules!.map<Widget>((item) {
|
||||
try {
|
||||
return switch (item.moduleType) {
|
||||
//
|
||||
'MODULE_TYPE_TITLE' => SliverToBoxAdapter(
|
||||
child: Text(
|
||||
item.moduleTitle!.text!,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//
|
||||
'MODULE_TYPE_AUTHOR' => SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed('/member?mid=${item.moduleAuthor?.mid}');
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
width: 40,
|
||||
height: 40,
|
||||
type: 'avatar',
|
||||
src: item.moduleAuthor?.face,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.moduleAuthor!.name!,
|
||||
style: TextStyle(
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
if (item.moduleAuthor?.pubTime != null)
|
||||
Text(
|
||||
item.moduleAuthor!.pubTime!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
fontSize: Theme.of(context)
|
||||
.textTheme
|
||||
.labelSmall!
|
||||
.fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//
|
||||
'MODULE_TYPE_CONTENT' => SliverList.separated(
|
||||
itemCount: item.moduleContent!.paragraphs!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final element = item.moduleContent!.paragraphs![index];
|
||||
|
||||
if ((element.paraType == 1 || element.paraType == 4)) {
|
||||
return SelectableText.rich(
|
||||
textAlign: element.align == 1 ? TextAlign.center : null,
|
||||
TextSpan(
|
||||
children: element.text?.nodes!.map<TextSpan>((item) {
|
||||
if (item.rich != null) {
|
||||
return TextSpan(
|
||||
text: '\u{1F517}${item.rich?.text}',
|
||||
style: TextStyle(
|
||||
decoration: item.rich?.style?.strikethrough == true
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
fontStyle: item.rich?.style?.italic == true
|
||||
? FontStyle.italic
|
||||
: null,
|
||||
fontWeight: item.rich?.style?.bold == true
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
if (item.rich!.jumpUrl != null) {
|
||||
PiliScheme.routePushFromUrl(
|
||||
item.rich!.jumpUrl!);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
return TextSpan(
|
||||
text: item.word?.words,
|
||||
style: TextStyle(
|
||||
decoration: item.word?.style?.strikethrough == true
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
fontStyle: item.word?.style?.italic == true
|
||||
? FontStyle.italic
|
||||
: null,
|
||||
fontWeight: item.word?.style?.bold == true
|
||||
? FontWeight.bold
|
||||
: null,
|
||||
color: item.word?.color != null
|
||||
? Color(item.word!.color!)
|
||||
: null,
|
||||
fontSize: item.word?.fontSize,
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
);
|
||||
}
|
||||
|
||||
if (element.paraType == 2) {
|
||||
element.pic!.pics!.first.onCalHeight(maxWidth);
|
||||
return Hero(
|
||||
tag: element.pic!.pics!.first.url!,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (callback != null) {
|
||||
callback(
|
||||
[element.pic!.pics!.first.url!],
|
||||
0,
|
||||
);
|
||||
} else {
|
||||
context.imageView(
|
||||
initialPage: 0,
|
||||
imgList: [
|
||||
SourceModel(url: element.pic!.pics!.first.url!)
|
||||
],
|
||||
);
|
||||
}
|
||||
},
|
||||
child: NetworkImgLayer(
|
||||
width: maxWidth,
|
||||
height: element.pic!.pics!.first.calHeight,
|
||||
src: element.pic!.pics!.first.url!,
|
||||
quality: 60,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (element.paraType == 3) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: Utils.thumbnailImgUrl(element.line!.pic!.url!),
|
||||
height: element.line?.pic?.height,
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const SizedBox(height: 10),
|
||||
),
|
||||
|
||||
//
|
||||
_ => const SliverToBoxAdapter(),
|
||||
};
|
||||
} catch (e) {
|
||||
return SliverToBoxAdapter(child: Text(e.toString()));
|
||||
}
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user