import 'package:flutter/material.dart';

import '../utils/utils.dart';

class ShowImageCache extends StatefulWidget {
  const ShowImageCache({Key? key}) : super(key: key);

  @override
  _ShowImageCacheState createState() => _ShowImageCacheState();
}

class _ShowImageCacheState extends State<ShowImageCache> {
  ImageCache? get imageCache => _imageCache;
  ImageCache? _imageCache = PaintingBinding.instance?.imageCache;
  @override
  void initState() {
    super.initState();
    _imageCache = PaintingBinding.instance?.imageCache;
  }

  void refresh() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
      const SizedBox(height: 8),
      ElevatedButton(onPressed: refresh, child: const Text('刷新缓存信息')),
      const SizedBox(height: 8),
      Text(
        '当前图像缓存数量: ${imageCache?.currentSize ?? 0} 大小: ${imageCache?.currentSizeBytes ?? 0}bytes = ${byte2MB(imageCache?.currentSizeBytes ?? 0)}MB',
        style: const TextStyle(fontSize: 12),
      ),
      const SizedBox(height: 8),
    ]);
  }
}

// ImageCache? get imageCache => PaintingBinding.instance?.imageCache;
// @override
//   Widget build(BuildContext context) {
//     return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
//       const SizedBox(height: 8),
//       Text(
//         '当前图像缓存数量: ${imageCache?.currentSize ?? 0}',
//         style: const TextStyle(fontSize: 12),
//       ),
//       const SizedBox(height: 8),
//       Text(
//         '当前图像缓存大小: ${imageCache?.currentSizeBytes ?? 0}bytes = ${byte2MB(imageCache?.currentSizeBytes ?? 0)}MB',
//         style: const TextStyle(fontSize: 12),
//       ),
//       const SizedBox(height: 8),
//     ]);
//   }