Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMPLE CODE FOR CACHE SUPPORT (LOAD THE MODEL 40% FASTER) #16

Open
seel-channel opened this issue Oct 13, 2020 · 0 comments
Open

SIMPLE CODE FOR CACHE SUPPORT (LOAD THE MODEL 40% FASTER) #16

seel-channel opened this issue Oct 13, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@seel-channel
Copy link

CACHE SUPPORT WITH FLUTTER CACHE MANAGER

import 'package:flutter/material.dart';
import 'package:pedantic/pedantic.dart';
import 'package:model_viewer/model_viewer.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';

...

@override
  Widget build(BuildContext context) {
    return FutureBuilder<String>(
      future: chached3DSrc(src),
      builder: (__, AsyncSnapshot<String> snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return ModelViewer(
            src: snapshot.data,
            autoPlay: true,
            autoRotate: true,
            autoRotateDelay: 0,
            cameraControls: true,
          );
        } else {
          return SizedBox();
        }
      },
    );
  }

  Future<String> chached3DSrc(String source) async {
    final BaseCacheManager _cacheManager = DefaultCacheManager();
    final fileInfo = await _cacheManager.getFileFromCache(source);

    if (fileInfo == null || fileInfo.file == null) {
      unawaited(_cacheManager.downloadFile(source));
      return source;
    } else {
      return "file://" + fileInfo.file.path;
    }
  }
@seel-channel seel-channel added the enhancement New feature or request label Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant