|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:forui/forui.dart'; |
| 5 | +import 'package:hooks_riverpod/hooks_riverpod.dart'; |
| 6 | +import 'package:miru_app_new/model/extension_meta_data.dart'; |
| 7 | +import 'package:miru_app_new/pages/index.dart'; |
| 8 | +import 'package:miru_app_new/provider/detial_provider.dart'; |
| 9 | +import 'package:miru_app_new/utils/store/database_service.dart'; |
| 10 | + |
| 11 | +import 'package:miru_app_new/widgets/error.dart'; |
| 12 | +import 'package:miru_app_new/widgets/index.dart'; |
| 13 | + |
| 14 | +class DetailLoadPage extends StatefulHookConsumerWidget { |
| 15 | + const DetailLoadPage({super.key, required this.meta, required this.url}); |
| 16 | + final ExtensionMeta meta; |
| 17 | + final String url; |
| 18 | + |
| 19 | + @override |
| 20 | + createState() => _DetailLoadPageState(); |
| 21 | +} |
| 22 | + |
| 23 | +class _DetailLoadPageState extends ConsumerState<DetailLoadPage> { |
| 24 | + @override |
| 25 | + void initState() { |
| 26 | + Future.microtask(() async { |
| 27 | + final history = await DatabaseService.getHistoryByPackageAndUrl( |
| 28 | + widget.meta.packageName, |
| 29 | + widget.url, |
| 30 | + ); |
| 31 | + ref.read(detialProvider.notifier).putHistory(history); |
| 32 | + }); |
| 33 | + // Trigger detail fetch via DetialProvider so UI doesn't depend directly on the fetch provider |
| 34 | + Future.microtask( |
| 35 | + () => ref |
| 36 | + .read(detialProvider.notifier) |
| 37 | + .fetchDetail(widget.meta.packageName, widget.url), |
| 38 | + ); |
| 39 | + super.initState(); |
| 40 | + } |
| 41 | + |
| 42 | + @override |
| 43 | + Widget build(BuildContext context) { |
| 44 | + final detial = |
| 45 | + ref.watch(detialProvider).detailState ?? const AsyncValue.loading(); |
| 46 | + return MiruScaffold( |
| 47 | + mobileHeader: SizedBox(), |
| 48 | + body: detial.when( |
| 49 | + data: (detial) => LoadedContent(detail: detial, meta: widget.meta), |
| 50 | + error: (err, stack) => ErrorDisplay.network(err: err, stack: stack), |
| 51 | + loading: () => Center(child: FCircularProgress()), |
| 52 | + ), |
| 53 | + ); |
| 54 | + } |
| 55 | + // { |
| 56 | + // final tancontroller = useTabController(initialLength: _trackingTab.length); |
| 57 | + // final snapShot = |
| 58 | + // ref.watch(detialProvider).detailState ?? const AsyncValue.loading(); |
| 59 | + // final isdropDown = useState(false); |
| 60 | + // final epGroup = useState(<ExtensionEpisodeGroup>[]); |
| 61 | + // return MiruScaffold( |
| 62 | + // mobileHeader: Align( |
| 63 | + // alignment: Alignment.centerLeft, |
| 64 | + // child: MoonButton( |
| 65 | + // label: const Text( |
| 66 | + // 'Detail', |
| 67 | + // style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), |
| 68 | + // ), |
| 69 | + // onTap: () { |
| 70 | + // context.pop(); |
| 71 | + // }, |
| 72 | + // leading: const Icon(MoonIcons.controls_chevron_left_16_regular), |
| 73 | + // ), |
| 74 | + // ), |
| 75 | + // sidebar: |
| 76 | + // DeviceUtil.isMobileLayout(context) |
| 77 | + // ? <Widget>[ |
| 78 | + // const SizedBox(height: 10), |
| 79 | + // Row( |
| 80 | + // children: <Widget>[ |
| 81 | + // Consumer( |
| 82 | + // builder: (context, ref, _) { |
| 83 | + // final hist = ref.watch(detialProvider).history; |
| 84 | + // return MoonButton( |
| 85 | + // onTap: |
| 86 | + // hist == null |
| 87 | + // ? null |
| 88 | + // : () { |
| 89 | + // final state = |
| 90 | + // ref.watch(detialProvider).detailState; |
| 91 | + // state?.whenData((data) { |
| 92 | + // if (data.episodes == null || |
| 93 | + // data.episodes!.isEmpty) { |
| 94 | + // return; |
| 95 | + // } |
| 96 | + // context.push( |
| 97 | + // '/watch', |
| 98 | + // extra: WatchParams( |
| 99 | + // name: hist.title, |
| 100 | + // detailImageUrl: data.cover ?? '', |
| 101 | + // selectedEpisodeIndex: hist.episodeId, |
| 102 | + // selectedGroupIndex: |
| 103 | + // hist.episodeGroupId, |
| 104 | + // epGroup: data.episodes, |
| 105 | + // detailUrl: widget.url, |
| 106 | + // url: |
| 107 | + // data |
| 108 | + // .episodes![hist |
| 109 | + // .episodeGroupId] |
| 110 | + // .urls[hist.episodeId] |
| 111 | + // .url, |
| 112 | + // meta: widget.meta, |
| 113 | + // type: widget.meta.type, |
| 114 | + // ), |
| 115 | + // ); |
| 116 | + // }); |
| 117 | + // }, |
| 118 | + // label: const Text('play'), |
| 119 | + // leading: const Icon(MoonIcons.media_play_24_regular), |
| 120 | + // ); |
| 121 | + // }, |
| 122 | + // ), |
| 123 | + // SizedBox( |
| 124 | + // width: DeviceUtil.getWidth(context) / 3, |
| 125 | + // child: MoonDropdown( |
| 126 | + // dropdownAnchorPosition: MoonDropdownAnchorPosition.top, |
| 127 | + // show: isdropDown.value, |
| 128 | + // content: Column( |
| 129 | + // children: List.generate( |
| 130 | + // epGroup.value.length, |
| 131 | + // (index) => MoonMenuItem( |
| 132 | + // label: Text( |
| 133 | + // overflow: TextOverflow.ellipsis, |
| 134 | + // epGroup.value[index].title, |
| 135 | + // style: TextStyle(), |
| 136 | + // ), |
| 137 | + // onTap: () { |
| 138 | + // ref |
| 139 | + // .read(detialProvider) |
| 140 | + // .setSelectedGroup(index); |
| 141 | + // isdropDown.value = false; |
| 142 | + // }, |
| 143 | + // ), |
| 144 | + // ), |
| 145 | + // ), |
| 146 | + // child: Consumer( |
| 147 | + // builder: (context, ref, _) { |
| 148 | + // final sel = |
| 149 | + // ref.watch(detialProvider).selectedGroup.value; |
| 150 | + // return MoonButton( |
| 151 | + // label: Text( |
| 152 | + // overflow: TextOverflow.ellipsis, |
| 153 | + // epGroup.value.isEmpty |
| 154 | + // ? 'No Season' |
| 155 | + // : epGroup.value[sel].title, |
| 156 | + // ), |
| 157 | + // onTap: () { |
| 158 | + // isdropDown.value = !isdropDown.value; |
| 159 | + // }, |
| 160 | + // ); |
| 161 | + // }, |
| 162 | + // ), |
| 163 | + // ), |
| 164 | + // ), |
| 165 | + // MoonButton( |
| 166 | + // label: const Text('WebView'), |
| 167 | + // onTap: () { |
| 168 | + // context.push( |
| 169 | + // '/mobileWebView', |
| 170 | + // extra: WebviewParam( |
| 171 | + // url: widget.url, |
| 172 | + // meta: widget.meta, |
| 173 | + // ), |
| 174 | + // ); |
| 175 | + // }, |
| 176 | + // leading: const Icon(MoonIcons.generic_globe_24_regular), |
| 177 | + // ), |
| 178 | + // ], |
| 179 | + // ), |
| 180 | + // const SizedBox(height: 10), |
| 181 | + // MoonTabBar( |
| 182 | + // tabController: tancontroller, |
| 183 | + // tabs: List.generate( |
| 184 | + // _trackingTab.length, |
| 185 | + // (index) => MoonTab(label: Text(_trackingTab[index])), |
| 186 | + // ), |
| 187 | + // ), |
| 188 | + // const SizedBox(height: 10), |
| 189 | + // SizedBox( |
| 190 | + // height: 200, |
| 191 | + // child: TabBarView( |
| 192 | + // controller: tancontroller, |
| 193 | + // children: [Container(), Container()], |
| 194 | + // ), |
| 195 | + // ), |
| 196 | + // ] |
| 197 | + // : null, |
| 198 | + // body: snapShot.when( |
| 199 | + // data: (data) { |
| 200 | + // epGroup.value = data.episodes ?? []; |
| 201 | + // return MediaQuery.removePadding( |
| 202 | + // context: context, |
| 203 | + // child: PlatformWidget( |
| 204 | + // mobileWidget: MobileDetail( |
| 205 | + // detailUrl: widget.url, |
| 206 | + // isLoading: false, |
| 207 | + // data: data, |
| 208 | + // meta: widget.meta, |
| 209 | + // ep: DetailEpButton( |
| 210 | + // detail: data, |
| 211 | + // notifier: ref.watch(detialProvider).selectedGroup, |
| 212 | + // onTap: (value) { |
| 213 | + // context.push( |
| 214 | + // '/watch', |
| 215 | + // extra: WatchParams( |
| 216 | + // detailUrl: widget.url, |
| 217 | + // detailImageUrl: data.cover ?? '', |
| 218 | + // name: data.title, |
| 219 | + // selectedEpisodeIndex: value, |
| 220 | + // selectedGroupIndex: |
| 221 | + // ref.watch(detialProvider).selectedGroup.value, |
| 222 | + // epGroup: data.episodes, |
| 223 | + // url: |
| 224 | + // data |
| 225 | + // .episodes![ref |
| 226 | + // .watch(detialProvider) |
| 227 | + // .selectedGroup |
| 228 | + // .value] |
| 229 | + // .urls[value] |
| 230 | + // .url, |
| 231 | + // meta: widget.meta, |
| 232 | + // type: widget.meta.type, |
| 233 | + // ), |
| 234 | + // ); |
| 235 | + // }, |
| 236 | + // spacing: 8, |
| 237 | + // runSpacing: 10, |
| 238 | + // ), |
| 239 | + // desc: Text( |
| 240 | + // maxLines: 3, |
| 241 | + // overflow: TextOverflow.ellipsis, |
| 242 | + // data.desc ?? 'No Description', |
| 243 | + // style: const TextStyle(fontSize: 12), |
| 244 | + // ), |
| 245 | + // ), |
| 246 | + // desktopWidget: DesktopDetail( |
| 247 | + // isLoading: false, |
| 248 | + // detailUrl: widget.url, |
| 249 | + // data: data, |
| 250 | + // extensionMeta: widget.meta, |
| 251 | + // ep: DetailEpButton( |
| 252 | + // notifier: ref.watch(detialProvider).selectedGroup, |
| 253 | + // detail: data, |
| 254 | + // onTap: (value) { |
| 255 | + // context.push( |
| 256 | + // '/watch', |
| 257 | + // extra: WatchParams( |
| 258 | + // name: data.title, |
| 259 | + // detailImageUrl: data.cover ?? '', |
| 260 | + // selectedEpisodeIndex: value, |
| 261 | + // selectedGroupIndex: |
| 262 | + // ref.watch(detialProvider).selectedGroup.value, |
| 263 | + // epGroup: data.episodes, |
| 264 | + // detailUrl: widget.url, |
| 265 | + // url: |
| 266 | + // data |
| 267 | + // .episodes![ref |
| 268 | + // .watch(detialProvider) |
| 269 | + // .selectedGroup |
| 270 | + // .value] |
| 271 | + // .urls[value] |
| 272 | + // .url, |
| 273 | + // meta: widget.meta, |
| 274 | + // type: widget.meta.type, |
| 275 | + // ), |
| 276 | + // ); |
| 277 | + // }, |
| 278 | + // spacing: 20, |
| 279 | + // runSpacing: 10, |
| 280 | + // ), |
| 281 | + // season: Column( |
| 282 | + // mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 283 | + // children: List.generate( |
| 284 | + // (data.episodes ?? []).length, |
| 285 | + // (index) => MoonChip( |
| 286 | + // width: double.infinity, |
| 287 | + // height: 30, |
| 288 | + // isActive: false, |
| 289 | + |
| 290 | + // label: Expanded(child: Text(data.episodes![index].title)), |
| 291 | + // onTap: () { |
| 292 | + // ref.read(detialProvider).setSelectedGroup(index); |
| 293 | + // }, |
| 294 | + // // backgroundColor: Theme.of(context).primaryColor, |
| 295 | + // ), |
| 296 | + // ), |
| 297 | + // ), |
| 298 | + // desc: Text( |
| 299 | + // data.desc ?? 'No Description', |
| 300 | + // style: const TextStyle(fontSize: 16), |
| 301 | + // ), |
| 302 | + // // cast: _DetailCast(), |
| 303 | + // ), |
| 304 | + // ), |
| 305 | + // ); |
| 306 | + // }, |
| 307 | + // loading: |
| 308 | + // () => PlatformWidget( |
| 309 | + // mobileWidget: MobileDetail( |
| 310 | + // isLoading: true, |
| 311 | + // meta: widget.meta, |
| 312 | + // desc: const LoadingWidget( |
| 313 | + // lineCount: 3, |
| 314 | + // lineheight: 8, |
| 315 | + // lineSeperate: 8, |
| 316 | + // padding: EdgeInsets.all(5), |
| 317 | + // ), |
| 318 | + // ep: const LoadingWidget( |
| 319 | + // lineCount: 3, |
| 320 | + // lineheight: 20, |
| 321 | + // lineSeperate: 15, |
| 322 | + // padding: EdgeInsets.all(5), |
| 323 | + // ), |
| 324 | + // ), |
| 325 | + // desktopWidget: DesktopDetail( |
| 326 | + // isLoading: true, |
| 327 | + // // cast: const LoadingWidget(lineCount: 8, lineheight: 20), |
| 328 | + // ep: const LoadingWidget(lineCount: 8, lineheight: 20), |
| 329 | + // season: const LoadingWidget(lineCount: 4, lineheight: 20), |
| 330 | + // desc: const LoadingWidget(lineCount: 8, lineheight: 20), |
| 331 | + // extensionMeta: widget.meta, |
| 332 | + // ), |
| 333 | + // ), |
| 334 | + // error: (err, stack) => ErrorDisplay.network(err: err, stack: stack), |
| 335 | + // ), |
| 336 | + // ); |
| 337 | + // } |
| 338 | +} |
0 commit comments