computed_value_notifier 0.0.1 copy "computed_value_notifier: ^0.0.1" to clipboard
computed_value_notifier: ^0.0.1 copied to clipboard

Computed value based on another Listenable or Listenables

example/lib/main.dart

import 'package:flutter/material.dart';

import 'form_view_model.dart';

void main(List<String> args) {
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

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

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

class _HomeState extends State<Home> {
  late final FormViewModel formViewModel;

  @override
  void initState() {
    super.initState();
    formViewModel = FormViewModel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Computed Value Notifier Example')),
      body: Center(
        child: FractionallySizedBox(
          widthFactor: 0.8,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TextField(
                decoration: const InputDecoration(hintText: 'Email'),
                onChanged: (newValue) => formViewModel.email.value = newValue,
              ),
              const SizedBox(height: 10),
              TextField(
                obscureText: true,
                decoration: const InputDecoration(hintText: 'Password'),
                onChanged: (newValue) =>
                    formViewModel.password.value = newValue,
              ),
              const SizedBox(height: 10),
              ValueListenableBuilder<bool>(
                  valueListenable: formViewModel.canLogin,
                  child: const Text('Log In'),
                  builder: (context, canLogin, child) {
                    return ElevatedButton(
                      onPressed: canLogin ? () {} : null,
                      child: child,
                    );
                  })
            ],
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    formViewModel.dispose();
    super.dispose();
  }
}
1
likes
130
pub points
4%
popularity

Publisher

unverified uploader

Computed value based on another Listenable or Listenables

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on computed_value_notifier