import 'dart:async'; import 'package:flutter/material.dart'; import 'story_detail_page.dart'; class StoryLoadingPage extends StatefulWidget { const StoryLoadingPage({super.key}); @override State createState() => _StoryLoadingPageState(); } class _StoryLoadingPageState extends State with SingleTickerProviderStateMixin { double _progress = 0.0; String _loadingText = "构思故事中..."; final List> _milestones = [ {'pct': 0.2, 'text': "正在收集灵感碎片..."}, {'pct': 0.5, 'text': "正在往故事里撒魔法粉..."}, {'pct': 0.8, 'text': "正在编制最后的魔法..."}, {'pct': 0.98, 'text': "大功告成!"}, ]; @override void initState() { super.initState(); _startLoading(); } void _startLoading() { // Total duration approx 3.5s (match Web 35ms * 100 steps) Timer.periodic(const Duration(milliseconds: 35), (timer) { if (!mounted) { timer.cancel(); return; } setState(() { _progress += 0.01; // Check text updates for (var m in _milestones) { if ((_progress - m['pct'] as double).abs() < 0.01) { _loadingText = m['text'] as String; } } }); if (_progress >= 1.0) { timer.cancel(); _navigateToDetail(); } }); } void _navigateToDetail() async { // Use push instead of pushReplacement to properly return the result final result = await Navigator.of(context).push( MaterialPageRoute( builder: (context) => StoryDetailPage( mode: StoryMode.generated, story: const { 'title': '星际忍者的茶话会', 'content': '在遥远的银河系边缘,有一个被星云包裹的神秘茶馆。今天,这里迎来了两位特殊的客人:刚执行完火星探测任务的宇航员波波,和正在追捕暗影怪兽的忍者小次郎。\n\n"这儿的重力好像有点不对劲?"波波飘在半空中,试图抓住飞来飞去的茶杯。小次郎则冷静地倒挂在天花板上,手里紧握着一枚手里剑——其实那是用来切月饼的。\n\n突然,桌上的魔法茶壶"噗"地一声喷出了七彩烟雾,一只会说话的卡皮巴拉钻了出来:"别打架,别打架,喝了这杯银河气泡茶,我们都是好朋友!"\n\n于是,宇宙中最奇怪的组合诞生了。他们决定,下一站,去黑洞边缘钓星星。', }, ), ), ); // Pass the result back to DeviceControlPage if (mounted) { Navigator.of(context).pop(result); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color(0xFFFDF9F3), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Image Image.asset( 'assets/www/kapi_writing.png', width: 200, height: 200, // Approximate errorBuilder: (c, e, s) => const Icon( Icons.edit_note, size: 100, color: Color(0xFFD1D5DB), ), ), const SizedBox(height: 32), // Text - HTML: font-size 18px, color #4B2404 (dark brown) Text( _loadingText, style: const TextStyle( fontSize: 18, // HTML: 18px color: Color(0xFF4B2404), // HTML: dark chocolate brown fontWeight: FontWeight.w600, ), ), const SizedBox(height: 24), // Progress Bar - HTML: height 12px, max-width 280px // Track: rgba(201,150,114,0.2), Fill: gradient #ECCFA8 to #C99672 Container( width: 280, // HTML: max-width 280px height: 12, // HTML: height 12px decoration: BoxDecoration( color: const Color(0xFFC99672).withOpacity(0.2), // Warm sand borderRadius: BorderRadius.circular(6), // HTML: 6px ), child: ClipRRect( borderRadius: BorderRadius.circular(6), child: FractionallySizedBox( alignment: Alignment.centerLeft, widthFactor: _progress.clamp(0.0, 1.0), child: Container( decoration: const BoxDecoration( // HTML: gradient #ECCFA8 to #C99672 gradient: LinearGradient( colors: [Color(0xFFECCFA8), Color(0xFFC99672)], ), ), ), ), ), ), ], ), ), ); } }