flutter_secure_file_storage 0.0.2 copy "flutter_secure_file_storage: ^0.0.2" to clipboard
flutter_secure_file_storage: ^0.0.2 copied to clipboard

outdated

An implementation for flutter secure file storage. For example keychain has a soft limit of 4kb. Using the file system instead we can store much larger content

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_secure_file_storage/flutter_secure_file_storage.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _content = '';
  String _loadedContent = '';
  String _key = '';
  bool _loading = false;
  late final FlutterSecureFileStorage _fileStorage;

  @override
  void initState() {
    super.initState();
    _fileStorage = FlutterSecureFileStorage(const FlutterSecureStorage());
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter secure file storage app'),
        ),
        body: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(8),
            child: Column(
              children: [
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Key',
                  ),
                  onChanged: (value) {
                    setState(() {
                      _key = value;
                    });
                  },
                ),
                TextField(
                  decoration: const InputDecoration(
                    labelText: 'Content',
                  ),
                  onChanged: (value) {
                    setState(() {
                      _content = value;
                    });
                  },
                ),
                MaterialButton(
                  child: const Text('Save'),
                  onPressed: () async {
                    setState(() {
                      _loading = true;
                    });
                    await _fileStorage.write(key: _key, value: _content);
                    setState(() {
                      _loading = false;
                    });
                  },
                ),
                MaterialButton(
                  child: const Text('Load from key'),
                  onPressed: () async {
                    setState(() {
                      _loading = true;
                    });
                    final content = await _fileStorage.read<String>(key: _key);
                    setState(() {
                      _loadedContent = content ?? '';
                      _loading = false;
                    });
                  },
                ),
                if (_loading) ...[
                  const CircularProgressIndicator(),
                ] else ...[
                  Text('Content from file: $_loadedContent'),
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}
11
likes
0
pub points
76%
popularity

Publisher

verified publishericapps.com

An implementation for flutter secure file storage. For example keychain has a soft limit of 4kb. Using the file system instead we can store much larger content

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

device_info_plus, flutter, flutter_secure_storage, path_provider, pointycastle

More

Packages that depend on flutter_secure_file_storage