import 'package:flutter/material.dart'; import 'package:voyagehandbook/util/drawer.dart'; import 'package:voyagehandbook/util/storage.dart'; import 'package:voyagehandbook/views/pageview.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class DownloadsView extends StatefulWidget { const DownloadsView({super.key}); @override State createState() => _DownloadsViewState(); } class _DownloadsViewState extends State { @override void initState() { super.initState(); loadDownloads(); } var _content = []; var _isLoading = true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(AppLocalizations.of(context)!.downloadsTitle), ), drawer: genDrawer(3, context), body: SizedBox( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width * 0.9, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: _isLoading ? [const CircularProgressIndicator()] : _content.isEmpty ? [Text(AppLocalizations.of(context)!.noDownloads)] : _content, ), ), ), ); } void loadDownloads() async { var files = await StorageAccess.offline; _content = List.generate( files.length, (index) => SizedBox( width: MediaQuery.of(context).size.width * 0.9, height: MediaQuery.of(context).size.height * 0.15, child: InkWell( onTap: () => Navigator.of(context).push( MaterialPageRoute( builder: (_) => ArticleView( pageKey: files[index]["key"], name: files[index]["title"], ), ), ), child: Padding( padding: const EdgeInsets.all(8), child: Text(files[index]["title"]), ), ), ), ); _isLoading = false; setState(() {}); } }