builder_when 1.1.1 copy "builder_when: ^1.1.1" to clipboard
builder_when: ^1.1.1 copied to clipboard

The BuilderWhen class is a simple yet powerful tool designed for Flutter applications.

example/lib/main.dart

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

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

class BuilderWhenPage extends StatelessWidget {
  const BuilderWhenPage({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: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool condition = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: BuilderWhen(
        condition: condition,
        isTrue: (context) => const Center(
          child: Text('True'),
        ),
        isFalse: (context) => const Center(
          child: Text('False'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => setState(() => condition = !condition),
        tooltip: 'Change',
        child: const Icon(Icons.add),
      ),
    );
  }
}
4
likes
160
points
29
downloads

Publisher

verified publisherjuarezfranco.com.br

Weekly Downloads

The BuilderWhen class is a simple yet powerful tool designed for Flutter applications.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on builder_when