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

A Flutter package that extends the standard TextField widget to add persistence capabilities. This package automatically saves and restores text input values using unique identifiers, making it perfec [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:persistent_textfield/persistent_textfield.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Basic Persistent Field'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    final TextEditingController controller = TextEditingController();

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(title),
      ),
      body: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            PersistentTextField(
              persistenceId: 'user_notes',
              controller: controller,
              decoration: const InputDecoration(
                labelText: 'Notes',
                hintText: 'Enter your notes here',
              ),
              onPersist: (value) {
                print('Text persisted: $value');
              },
            ),
            TextButton(
              onPressed: () {
                PersistentTextField.resetPersistedValue('user_notes');
                controller.clear();
              },
              child: const Text("Clear Field"),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
150
points
36
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that extends the standard TextField widget to add persistence capabilities. This package automatically saves and restores text input values using unique identifiers, making it perfect for forms, notes, or any scenario where you need to persist user input across app sessions.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on persistent_textfield