Improve comic display

This commit is contained in:
2025-01-06 21:41:52 +08:00
parent 08e8a45236
commit 91ee48cc6c
5 changed files with 123 additions and 110 deletions

View File

@@ -235,29 +235,30 @@ class ComicTile extends StatelessWidget {
} }
Widget _buildBriefMode(BuildContext context) { Widget _buildBriefMode(BuildContext context) {
return Padding( return LayoutBuilder(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
child: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
return InkWell( return InkWell(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
onTap: _onTap, onTap: _onTap,
onLongPress: onLongPress: enableLongPressed ? () => _onLongPressed(context) : null,
enableLongPressed ? () => _onLongPressed(context) : null,
onSecondaryTapDown: (detail) => onSecondaryTap(detail, context), onSecondaryTapDown: (detail) => onSecondaryTap(detail, context),
child: Column( child: Column(
children: [ children: [
Expanded( Expanded(
child: SizedBox(
child: Stack( child: Stack(
children: [ children: [
Positioned.fill( Positioned.fill(
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context) color: context.colorScheme.secondaryContainer,
.colorScheme
.secondaryContainer,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.toOpacity(0.2),
blurRadius: 2,
offset: const Offset(0, 2),
),
],
), ),
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: buildImage(context), child: buildImage(context),
@@ -270,75 +271,73 @@ class ComicTile extends StatelessWidget {
comic.subtitle?.replaceAll('\n', '').trim(); comic.subtitle?.replaceAll('\n', '').trim();
final text = comic.description.isNotEmpty final text = comic.description.isNotEmpty
? comic.description.split('|').join('\n') ? comic.description.split('|').join('\n')
: (subtitle?.isNotEmpty == true : (subtitle?.isNotEmpty == true ? subtitle : null);
? subtitle final fortSize = constraints.maxWidth < 80
: null); ? 8.0
final scale = : constraints.maxWidth < 150
(appdata.settings['comicTileScale'] as num) ? 10.0
.toDouble(); : 12.0;
final fortSize = scale < 0.85
? 8.0 // 小尺寸
: (scale < 1.0 ? 10.0 : 12.0);
if (text == null) { if (text == null) {
return const SizedBox return const SizedBox();
.shrink(); // 如果没有文本,则不显示任何内容
} }
return Padding( var children = <Widget>[];
padding: const EdgeInsets.symmetric( for (var line in text.split('\n')) {
horizontal: 2, vertical: 2), children.add(Container(
child: ClipRRect( margin: const EdgeInsets.fromLTRB(2, 0, 2, 2),
borderRadius: const BorderRadius.all( padding: constraints.maxWidth < 80
Radius.circular(10.0), ? const EdgeInsets.fromLTRB(3, 1, 3, 1)
), : constraints.maxWidth < 150
child: Container( ? const EdgeInsets.fromLTRB(4, 2, 4, 2)
: const EdgeInsets.fromLTRB(5, 2, 5, 2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.black.toOpacity(0.5), color: Colors.black.toOpacity(0.5),
child: Padding( ),
padding:
const EdgeInsets.fromLTRB(8, 6, 8, 6),
child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
maxWidth: constraints.maxWidth, maxWidth: constraints.maxWidth,
), ),
child: Text( child: Text(
text, line,
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: fortSize, fontSize: fortSize,
color: Colors.white, color: Colors.white,
), ),
textAlign: TextAlign.right, textAlign: TextAlign.right,
maxLines: 2, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ));
), }
), return Column(
), mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: children,
); );
})(), })(),
), ),
], ],
), ),
), ),
),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(8, 4, 8, 0), padding: const EdgeInsets.fromLTRB(4, 4, 4, 0),
child: Text( child: TextScroll(
comic.title.replaceAll('\n', ''), comic.title.replaceAll('\n', ''),
mode: TextScrollMode.endless,
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
maxLines: 1, delayBefore: Duration(milliseconds: 500),
overflow: TextOverflow.ellipsis, velocity: const Velocity(pixelsPerSecond: Offset(40, 0)),
), ),
), ),
], ],
), ).paddingHorizontal(6).paddingVertical(8),
); );
}, },
)); );
} }
List<String> _splitText(String text) { List<String> _splitText(String text) {
@@ -807,7 +806,10 @@ class _SliverGridComics extends StatelessWidget {
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected color: isSelected
? Theme.of(context).colorScheme.secondaryContainer.toOpacity(0.72) ? Theme.of(context)
.colorScheme
.secondaryContainer
.toOpacity(0.72)
: null, : null,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),

View File

@@ -9,6 +9,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:syntax_highlight/syntax_highlight.dart'; import 'package:syntax_highlight/syntax_highlight.dart';
import 'package:text_scroll/text_scroll.dart';
import 'package:venera/foundation/app.dart'; import 'package:venera/foundation/app.dart';
import 'package:venera/foundation/app_page_route.dart'; import 'package:venera/foundation/app_page_route.dart';
import 'package:venera/foundation/appdata.dart'; import 'package:venera/foundation/appdata.dart';

View File

@@ -73,6 +73,7 @@ class FavoriteItem implements Comic {
@override @override
String get description { String get description {
var time = this.time.substring(0, 10);
return appdata.settings['comicDisplayMode'] == 'detailed' return appdata.settings['comicDisplayMode'] == 'detailed'
? "$time | ${type == ComicType.local ? 'local' : type.comicSource?.name ?? "Unknown"}" ? "$time | ${type == ComicType.local ? 'local' : type.comicSource?.name ?? "Unknown"}"
: "${type.comicSource?.name ?? "Unknown"} | $time"; : "${type.comicSource?.name ?? "Unknown"} | $time";

View File

@@ -968,6 +968,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.3" version: "0.7.3"
text_scroll:
dependency: "direct main"
description:
name: text_scroll
sha256: "7869d86a6fdd725dee56bdd150216a99f0372b82fbfcac319214dbd5f36e1908"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:

View File

@@ -72,6 +72,7 @@ dependencies:
shimmer: ^3.0.0 shimmer: ^3.0.0
flutter_memory_info: ^0.0.1 flutter_memory_info: ^0.0.1
syntax_highlight: ^0.4.0 syntax_highlight: ^0.4.0
text_scroll: ^0.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: