pikapika/lib/screens/DownloadExportToSocketScree...

113 lines
3.4 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Channels.dart';
import 'package:pikapika/basic/Entities.dart';
import 'package:pikapika/basic/Method.dart';
2021-09-29 23:57:09 +00:00
import 'components/ContentError.dart';
import 'components/ContentLoading.dart';
import 'components/DownloadInfoCard.dart';
2021-10-26 11:04:23 +00:00
// 传输到其他设备
2021-09-29 23:57:09 +00:00
class DownloadExportToSocketScreen extends StatefulWidget {
final DownloadComic task;
final String comicId;
final String comicTitle;
2022-03-17 03:31:25 +00:00
const DownloadExportToSocketScreen({
2021-09-29 23:57:09 +00:00
required this.task,
required this.comicId,
required this.comicTitle,
2022-03-17 03:31:25 +00:00
Key? key,
}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _DownloadExportToSocketScreenState();
}
class _DownloadExportToSocketScreenState
extends State<DownloadExportToSocketScreen> {
late Future<int> _future = method.exportComicUsingSocket(widget.comicId);
2022-03-17 03:31:25 +00:00
late final Future<String> _ipFuture = method.clientIpSet();
2021-09-29 23:57:09 +00:00
late String exportMessage = "";
@override
void initState() {
registerEvent(_onMessageChange, "EXPORT");
super.initState();
}
@override
void dispose() {
method.exportComicUsingSocketExit();
unregisterEvent(_onMessageChange);
super.dispose();
}
void _onMessageChange(event) {
if (event is String) {
setState(() {
exportMessage = event;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("网络导出 - " + widget.comicTitle),
),
body: FutureBuilder(
future: _future,
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
if (snapshot.hasError) {
return ContentError(
error: snapshot.error,
stackTrace: snapshot.stackTrace,
onRefresh: () async {
setState(() {
_future = method.exportComicUsingSocket(widget.comicId);
});
});
}
if (snapshot.connectionState != ConnectionState.done) {
2022-03-19 04:12:27 +00:00
return const ContentLoading(label: '加载中');
2021-09-29 23:57:09 +00:00
}
return ListView(
children: [
DownloadInfoCard(task: widget.task),
Container(
2022-03-19 04:12:27 +00:00
padding: const EdgeInsets.all(8),
2021-09-29 23:57:09 +00:00
child: Column(
children: [
2022-03-19 04:12:27 +00:00
const Text(
2021-09-29 23:57:09 +00:00
'TIPS : 传输成功之前请不要退出页面, 一次只能导出到一个设备, 两台设备需要在同一网段或无限局域网中, 请另外一台设备输入 IP:端口 , 有一个IP时请选择无限局域网的IP, 通常是192.168开头'),
FutureBuilder(
future: _ipFuture,
builder: (BuildContext context,
AsyncSnapshot<String> snapshot) {
if (snapshot.hasError) {
2022-03-17 03:31:25 +00:00
return const Text('获取IP失败');
2021-09-29 23:57:09 +00:00
}
if (snapshot.connectionState != ConnectionState.done) {
2022-03-17 03:31:25 +00:00
return const Text('正在获取IP');
2021-09-29 23:57:09 +00:00
}
return Text('${snapshot.data}');
},
),
Text('端口号:${snapshot.data}'),
2022-03-17 03:31:25 +00:00
Text(exportMessage),
2021-09-29 23:57:09 +00:00
],
),
),
],
);
},
),
);
}
}