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

adaptive_breakpoints with freezed functionality

example/lib/main.dart

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

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

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

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

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

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Adaptive"),
      ),
      body: AdaptiveBuilder(
        builder: (context, entry, constraints) {
          return entry.type.when(
            xs: () {
              return Text(
                "xs $_counter",
                style: const TextStyle(color: Colors.black, fontSize: 18),
              );
            },
            s: () {
              return Text(
                "s $_counter",
                style: const TextStyle(color: Colors.black, fontSize: 18),
              );
            },
            m: () {
              return Text(
                "m $_counter",
                style: const TextStyle(color: Colors.black, fontSize: 18),
              );
            },
            l: () {
              return Text(
                "l $_counter",
                style: const TextStyle(color: Colors.black, fontSize: 18),
              );
            },
            xl: () {
              return Text(
                "xl $_counter",
                style: const TextStyle(color: Colors.black, fontSize: 18),
              );
            },
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          context.adaptive.whenDevice(
            mobile: () {
              _counter++;
            },
            tablet: () {
              _counter += 2;
            },
            desktop: () {
              _counter += 4;
            },
          );
        },
        tooltip: 'Increment',
        child: context.adaptive.whenDevice(
          mobile: () => const Icon(Icons.screenshot),
          tablet: () => const Icon(Icons.tablet),
          desktop: () => const Icon(Icons.desktop_mac),
        ),
      ),
    );
  }
}
2
likes
110
pub points
49%
popularity

Publisher

unverified uploader

adaptive_breakpoints with freezed functionality

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, freezed_annotation

More

Packages that depend on adaptive_breakpoints_freezed