gh_asset_pre_cache 0.0.1 copy "gh_asset_pre_cache: ^0.0.1" to clipboard
gh_asset_pre_cache: ^0.0.1 copied to clipboard

A plug-in that improves the usability and performance of the app by pre-caching assets used in the application.

example/lib/main.dart

import 'package:example/pages/image_cache_page.dart';
import 'package:example/pages/image_non_cache_page.dart';
import 'package:flutter/material.dart';
import 'package:gh_asset_pre_cache/gh_asset_pre_cache.dart';

void main() {
  GhAssetPreCache().startImageCache();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      initialRoute: '/',
      routes: {
        '/': (context) => const FeatureList(),
        FeatureEnum.image.route: (context) => const ImageNonCachePage(),
        FeatureEnum.imageCache.route: (context) => const ImageCachePage(),
      },
    );
  }
}

class FeatureList extends StatelessWidget {
  const FeatureList({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        child: Center(child: _buildBody()),
      ),
    );
  }

  Widget _buildBody(){
    return ListView.builder(
      physics: const NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      itemCount: FeatureEnum.values.length,
      itemBuilder : listItem,
    );
  }

  Widget listItem(BuildContext context, int index){
    var currentFeature = FeatureEnum.values[index];
    return GestureDetector(
      onTap: currentFeature.onTap(context),
      child: Container(
        decoration: BoxDecoration(
            border: Border.all(color: Colors.black),
            borderRadius: const BorderRadius.all(Radius.circular(10))
        ),
        margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
        width: double.infinity,
        height: 70,
        alignment: Alignment.center,
        child: Text(currentFeature.name, style: const TextStyle(
          fontSize: 20,
        ),),
      ),
    );
  }
}

enum FeatureEnum{
  image('/image', 'image non cache'),
  imageCache('/imageCache', 'image cache');

  final String route;
  final String name;
  const FeatureEnum(this.route, this.name);

}
extension FeatureEnumExtention on FeatureEnum{
  VoidCallback onTap(BuildContext context) => (){Navigator.pushNamed(context, route);};
}
6
likes
0
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A plug-in that improves the usability and performance of the app by pre-caching assets used in the application.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_svg

More

Packages that depend on gh_asset_pre_cache