mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
add support for novel image
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:pixes/components/animated_image.dart';
|
||||
import 'package:pixes/components/loading.dart';
|
||||
import 'package:pixes/foundation/image_provider.dart';
|
||||
import 'package:pixes/network/network.dart';
|
||||
import 'package:pixes/pages/image_page.dart';
|
||||
import 'package:pixes/utils/ext.dart';
|
||||
|
||||
class NovelReadingPage extends StatefulWidget {
|
||||
const NovelReadingPage(this.novel, {super.key});
|
||||
@@ -14,31 +18,20 @@ class NovelReadingPage extends StatefulWidget {
|
||||
class _NovelReadingPageState extends LoadingState<NovelReadingPage, String> {
|
||||
@override
|
||||
Widget buildContent(BuildContext context, String data) {
|
||||
var content = buildList(context).toList();
|
||||
return ScaffoldPage(
|
||||
padding: EdgeInsets.zero,
|
||||
content: SelectionArea(
|
||||
child: SingleChildScrollView(
|
||||
child: DefaultTextStyle.merge(
|
||||
style: const TextStyle(fontSize: 16.0, height: 1.6),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(widget.novel.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 24.0, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12.0),
|
||||
const Divider(
|
||||
style: DividerThemeData(horizontalMargin: EdgeInsets.all(0)),
|
||||
),
|
||||
const SizedBox(height: 12.0),
|
||||
Text(data,
|
||||
style: const TextStyle(
|
||||
fontSize: 16.0,
|
||||
height: 1.6,
|
||||
)),
|
||||
],
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
return content[index];
|
||||
},
|
||||
itemCount: content.length,
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,4 +39,41 @@ class _NovelReadingPageState extends LoadingState<NovelReadingPage, String> {
|
||||
Future<Res<String>> loadData() {
|
||||
return Network().getNovelContent(widget.novel.id.toString());
|
||||
}
|
||||
|
||||
Iterable<Widget> buildList(BuildContext context) sync* {
|
||||
yield Text(widget.novel.title,
|
||||
style: const TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold));
|
||||
yield const SizedBox(height: 12.0);
|
||||
yield const Divider(
|
||||
style: DividerThemeData(horizontalMargin: EdgeInsets.all(0)),
|
||||
);
|
||||
yield const SizedBox(height: 12.0);
|
||||
|
||||
var novelContent = data!.split('\n');
|
||||
for (var content in novelContent) {
|
||||
if (content.isEmpty) continue;
|
||||
if (content.startsWith('[uploadedimage:')) {
|
||||
var imageId = content.nums;
|
||||
yield GestureDetector(
|
||||
onTap: () {
|
||||
ImagePage.show(["novel:${widget.novel.id.toString()}/$imageId"]);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 300,
|
||||
width: double.infinity,
|
||||
child: AnimatedImage(
|
||||
image:
|
||||
CachedNovelImageProvider(widget.novel.id.toString(), imageId),
|
||||
filterQuality: FilterQuality.medium,
|
||||
fit: BoxFit.contain,
|
||||
height: 300,
|
||||
width: double.infinity,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
yield Text(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user