shared_preferences_ios_sn 1.0.3 copy "shared_preferences_ios_sn: ^1.0.3" to clipboard
shared_preferences_ios_sn: ^1.0.3 copied to clipboard

PlatformiOS

Simply to wrap the Flutter plugin shared_preferences plugin and provide iOS "suite name" feature

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:shared_preferences_ios_sn/SPUtil.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'SharedPreferences Demo',
      home: SharedPreferencesDemo(),
    );
  }
}

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

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

class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {

  int _counter = 0;

  Future<void> _incrementCounter() async {

    /**
     * just instead of "SharedPreferences.getInstance()" with SPUtil.withSuitName()
     * 
     * and then all these datas can be shared to iOS Widget 
     */
    //final prefs = SharedPreferences.getInstance()
    final prefs = await SPUtil.withSuitName("group.my_test");


    final int counter = (prefs.getInt("test_key") ?? 0) + 1;
    prefs.setInt("test_key",counter);
    
    setState(() {
      _counter = counter;
    });
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SharedPreferences Demo'),
      ),
      body: Center(
          child: Text(_counter.toString())),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
4
likes
130
pub points
71%
popularity

Publisher

unverified uploader

Simply to wrap the Flutter plugin shared_preferences plugin and provide iOS "suite name" feature

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, meta, shared_preferences, shared_preferences_platform_interface

More

Packages that depend on shared_preferences_ios_sn