flutter_lean_extensions 1.0.0 copy "flutter_lean_extensions: ^1.0.0" to clipboard
flutter_lean_extensions: ^1.0.0 copied to clipboard

A collection of extensions and widgets that make life easier with minimal dependencies

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_lean_extensions/essentials.dart';
import 'package:flutter_lean_extensions/extensions.dart';

/// simple example of running a flutter app with this lib
void main() {
  runApp(const MyApp());
}

/// Root widget for the example app.
class MyApp extends StatelessWidget {
  /// default constructor.
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lean Extensions Demo',
      theme: ThemeData(
        useMaterial3: true,
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.deepPurple,
        ),
      ),
      home: const ExampleHome(),
    );
  }
}

/// Home page for the example app.
class ExampleHome extends StatelessWidget {
  /// default constructor.
  const ExampleHome({super.key});

  @override
  Widget build(BuildContext context) {
    // Context Extensions:
    // access theme, colorScheme, textTheme, and mediaSize
    final colorScheme = context.colorScheme;
    final textTheme = context.textTheme;
    final size = context.mediaSize;

    return Scaffold(
      appBar: AppBar(
        title: const Text('Lean Extensions'),
        backgroundColor: colorScheme.primaryContainer,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Text(
              '1. Context Extensions',
              style: textTheme.titleLarge?.copyWith(
                color: colorScheme.primary,
                fontWeight: FontWeight.bold,
              ),
            ),
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('Theme brightness: ${context.theme.brightness}'),
                    Text('Screen width: ${size.width.toStringAsFixed(1)}'),
                    Text('Screen height: ${size.height.toStringAsFixed(1)}'),
                  ]
                      // Separate internal rows with spacing:
                      .separateByHeight(8),
                ),
              ),
            ),

            // Section header
            Text(
              '2. Widget Extensions & ShrunkBox',
              style: textTheme.titleLarge?.copyWith(
                color: colorScheme.primary,
                fontWeight: FontWeight.bold,
              ),
            ),
            // Showcase withMaxSize and ShrunkBox
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16),
                child: Column(
                  children: <Widget>[
                    ElevatedButton(
                      onPressed: () {},
                      child: const Text('Unconstrained Button'),
                    ),
                    ElevatedButton(
                      onPressed: () {},
                      child: const Text('Button with Max Width (200)'),
                    )
                        // Constrain the maximum width of the button:
                        .withMaxSize(width: 200),
                    // ShrunkBox occupies no space:
                    const ShrunkBox(),
                  ]
                      // Separate children with spacing:
                      .separateByHeight(12),
                ),
              ),
            ),
          ]
              // Separate main sections with spacing:
              .separateByHeight(24),
        ),
      ),
    );
  }
}
0
likes
160
points
168
downloads

Documentation

API reference

Publisher

verified publisherel-darto.net

Weekly Downloads

A collection of extensions and widgets that make life easier with minimal dependencies

Repository

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_lean_extensions