|
| 1 | +// ignore_for_file: avoid_print |
| 2 | +import 'dart:async'; |
| 3 | + |
| 4 | +import 'package:data_asset_package/data_asset_package.dart'; |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | + |
| 7 | +import 'helper.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + runApp(const MyApp()); |
| 11 | +} |
| 12 | + |
| 13 | +class MyApp extends StatefulWidget { |
| 14 | + const MyApp({super.key}); |
| 15 | + |
| 16 | + @override |
| 17 | + State<MyApp> createState() => _MyAppState(); |
| 18 | +} |
| 19 | + |
| 20 | +class _MyAppState extends State<MyApp> { |
| 21 | + AssetData? _assetData; |
| 22 | + String _dependencyAsset = 'Loading...'; |
| 23 | + Timer? _timer; |
| 24 | + |
| 25 | + @override |
| 26 | + void initState() { |
| 27 | + super.initState(); |
| 28 | + _timer = Timer.periodic(const Duration(milliseconds: 500), (_) async { |
| 29 | + final data = await dumpAssets(); |
| 30 | + final depAsset = await readAsset(); |
| 31 | + // Print for integration test discovery |
| 32 | + if (data != null) { |
| 33 | + print('DUMPED ASSETS for ${data.version}'); |
| 34 | + } |
| 35 | + print('DEPENDENCY_ASSET: $depAsset'); |
| 36 | + |
| 37 | + if (mounted) { |
| 38 | + setState(() { |
| 39 | + if (data != null) { |
| 40 | + _assetData = data; |
| 41 | + } |
| 42 | + _dependencyAsset = depAsset; |
| 43 | + }); |
| 44 | + } |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + @override |
| 49 | + void dispose() { |
| 50 | + _timer?.cancel(); |
| 51 | + super.dispose(); |
| 52 | + } |
| 53 | + |
| 54 | + @override |
| 55 | + Widget build(BuildContext context) { |
| 56 | + return MaterialApp( |
| 57 | + title: 'Data Asset Demo', |
| 58 | + home: Scaffold( |
| 59 | + appBar: AppBar(title: const Text('Data Asset Demo')), |
| 60 | + body: ListView( |
| 61 | + padding: const EdgeInsets.all(16), |
| 62 | + children: [ |
| 63 | + Text('Version: ${_assetData?.version ?? "Unknown"}', style: Theme.of(context).textTheme.headlineSmall), |
| 64 | + const Divider(), |
| 65 | + const Text('Local Assets:', style: TextStyle(fontWeight: FontWeight.bold)), |
| 66 | + if (_assetData != null) ...[ |
| 67 | + if (_assetData!.found.isEmpty && _assetData!.notFound.isEmpty) |
| 68 | + const Text('No assets requested.'), |
| 69 | + for (final MapEntry(:key, :value) in _assetData!.found.entries) |
| 70 | + Text('FOUND "$key": "$value"'), |
| 71 | + for (final id in _assetData!.notFound) |
| 72 | + Text('NOT FOUND "$id"', style: const TextStyle(color: Colors.red)), |
| 73 | + ] else |
| 74 | + const Text('Loading assets...'), |
| 75 | + const Divider(), |
| 76 | + const Text('Dependency Asset:', style: TextStyle(fontWeight: FontWeight.bold)), |
| 77 | + Text(_dependencyAsset), |
| 78 | + ], |
| 79 | + ), |
| 80 | + ), |
| 81 | + ); |
| 82 | + } |
| 83 | +} |
0 commit comments