katana_prefs 1.1.6 copy "katana_prefs: ^1.1.6" to clipboard
katana_prefs: ^1.1.6 copied to clipboard

The base part of the package for type-safe use of retrieving and storing Shared Preferences values, defining data in a Freezed-like fashion.

example/lib/main.dart

import 'package:katana_prefs/katana_prefs.dart';

import 'package:flutter/material.dart';

part 'main.prefs.dart';

@prefs
class PrefsValue with _$PrefsValue, ChangeNotifier {
  factory PrefsValue({
    String? userToken,
    required double volumeSetting,
  }) = _PrefsValue;
  PrefsValue._();
}

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const PrefsPage(),
      title: "Flutter Demo",
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
    );
  }
}

class PrefsPage extends StatefulWidget {
  const PrefsPage({super.key});

  @override
  State<StatefulWidget> createState() => PrefsPageState();
}

class PrefsPageState extends State<PrefsPage> {
  final prefs = PrefsValue(volumeSetting: 0.5);

  @override
  void initState() {
    super.initState();
    prefs.addListener(() {
      setState(() {});
    });
    prefs.load();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Flutter Demo")),
      body: ListView(
        children: [
          ListTile(
            title: TextField(
              controller: TextEditingController(text: prefs.userToken.get()),
              onChanged: (val) async {
                await prefs.userToken.set(val);
              },
            ),
          ),
          const Padding(
            padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            child: Text("Volume Settings"),
          ),
          ListTile(
            title: Slider(
              value: prefs.volumeSetting.get(),
              onChanged: (val) {
                prefs.volumeSetting.set(val);
              },
            ),
            trailing: Text(
              "${prefs.volumeSetting.get().toStringAsFixed(1)}/1.0",
            ),
          ),
        ],
      ),
    );
  }
}
0
likes
0
pub points
50%
popularity

Publisher

verified publishermathru.net

The base part of the package for type-safe use of retrieving and storing Shared Preferences values, defining data in a Freezed-like fashion.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, katana, katana_prefs_annotation, shared_preferences

More

Packages that depend on katana_prefs