import 'package:flutter/material.dart'; import '../../api/oa_client.dart'; import '../desk_theme.dart'; import '../widgets/desk_widgets.dart'; class DeskLegalPage extends StatefulWidget { const DeskLegalPage({super.key, required this.api, required this.kind}); final OaClient api; final String kind; @override State createState() => _DeskLegalPageState(); } class _DeskLegalPageState extends State { String _title = ''; List> _sections = []; String _error = ''; bool _loading = true; @override void initState() { super.initState(); _load(); } Future _load() async { try { final raw = await widget.api.get('/legal/${widget.kind}'); if (!mounted) return; if (raw is Map) { final data = Map.from(raw); final paras = asMaps(data['paragraphs']); setState(() { _title = '${data['title'] ?? ''}'; _sections = paras.isNotEmpty ? paras.map((e) => {'title': '${e['heading'] ?? e['title'] ?? ''}', 'body': '${e['body'] ?? ''}'}).toList() : [{'title': '', 'body': '${data['body'] ?? data['content'] ?? ''}'}]; _loading = false; }); } } catch (e) { if (mounted) setState(() { _error = '$e'; _loading = false; }); } } @override Widget build(BuildContext context) { return ColoredBox( color: kDeskBg, child: Column( children: [ DeskPaneHeader( title: _title.isEmpty ? (widget.kind == 'privacy' ? '隐私政策' : '用户协议') : _title, leading: IconButton(icon: const Icon(Icons.arrow_back, size: 20), onPressed: () => Navigator.pop(context)), ), if (_loading) const LinearProgressIndicator(minHeight: 2, color: kDeskBind), Expanded( child: _error.isNotEmpty ? Center(child: Text(_error, style: const TextStyle(color: kDeskMute))) : ListView( padding: const EdgeInsets.all(24), children: [ for (final s in _sections) ...[ Text(s['title'] ?? '', style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600)), const SizedBox(height: 8), Text(s['body'] ?? '', style: const TextStyle(fontSize: 14, height: 1.6, color: kDeskInk)), const SizedBox(height: 20), ], ], ), ), ], ), ); } }