'store file metadata and retrieve the file later (in web)

I have a cross platform application for uploading files and I want to add the resume capability to the application. In the native version I can simply save the path of the file and retrieve the file later and split it and send the remaining of the file. but in the web version for that I have to store the whole file (in binary) to the web storage (by reading and creating the binary)(like: indexedDB or cacheAPI) and for retrieving I have to get the binary and put it into the file.

I wonder is there some way that I can save the metadata of the file and then access to the file. (not reading and storing the whole file in binary)

reading the file:

const fileToBinary = async (file: File) => {

    return new Promise<string>((resolve, _) => {
      const success = (event) => {
        resolve(event.target.result);
      }
      
      const fileReader = new FileReader();
      fileReader.addEventListener('load', success);
      fileReader.readAsBinaryString(file);
    });
  }

Retrieving from binary:

const binaryToByte = (binary: string, progress?: number) => {
    let bytes = new Uint8Array(binary.length);
    for (let i=0; i<binary.length; i++)
      bytes[i] = binary.charCodeAt(i);
    
    return bytes.slice(progress, binary.length);
  }

Creating file from binary:

const bytes = binaryToByte(blob.binary, progress);
const _blob = new Blob([bytes], {type: blob.type});
const file = new File([_blob], blob.name, {type: blob.type, lastModified: blob.lastModified});


Solution 1:[1]

You can use this https://pub.dev/packages/flutter_native_splash its easy to use,

Solution 2:[2]

Try to add timer in initState instead of what you doing something like this ‘void initState() {
super.initState();
Timer(Duration(seconds: 5),
()=>Navigator.pushReplacement(context,
MaterialPageRoute(builder:
(context) => HomeScreen()
)
)
);
}

Solution 3:[3]

Method 1
You can use animated_splash_screen its easy to use,

home: AnimatedSplashScreen(
    splash: Scaffold(
      body: Center(
        child: Image.asset(
          'assets/logo.png',
          width: double.infinity,
          height: double.infinity,
        ),
      ),
    ),
    duration: 100,
    nextScreen: Login(),
    splashTransition: SplashTransition.fadeTransition,
    backgroundColor: Colors.white,

Method 2

Or Use Timer for delay some seconds in the initState()

Timer(
      Duration(seconds: 2),
      () => Navigator.pushReplacement(context,
          MaterialPageRoute(builder: (context) => HomePage())));

Solution 4:[4]

class _SplashState extends State<Splash> {
  
  @override
  void initState() {
    super.initState();
    Timer(Duration(seconds: 3),
            ()=>Navigator.pushReplacement(context,
            MaterialPageRoute(builder:
                (context) =>First()
            )
        )
    );
  }

 return Scaffold(
      body: SizedBox.expand(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              child: Image.asset('Assets/Group.png'),
              padding: const EdgeInsets.all(8.0),
              height: 200,
              width: 200,
            ),
            CircularProgressIndicator(color: HexColor('#22178F'),),
          ],
        ),
      ),
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gowthaman C
Solution 2 shanmkha
Solution 3
Solution 4