storybook_flutter 0.9.0-dev.1 copy "storybook_flutter: ^0.9.0-dev.1" to clipboard
storybook_flutter: ^0.9.0-dev.1 copied to clipboard

outdated

A storybook for Flutter widgets. Live preview of isolated widgets for faster development and showcase.

example/lib/main.dart

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

void main() => runApp(const MyApp());

final _plugins = initializePlugins(
  contentsSidePanel: true,
  knobsSidePanel: true,
  initialDeviceFrameData: DeviceFrameData(
    device: Devices.ios.iPhone13,
  ),
);

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

  @override
  Widget build(BuildContext context) => Storybook(
        initialStory: 'Scaffold',
        plugins: _plugins,
        stories: [
          Story(
            name: 'Button',
            builder: (context) => TextButton(
              onPressed: () => showDialog<void>(
                context: context,
                builder: (context) => const AlertDialog(
                  title: Text('Hello'),
                  content: Text('Hello World!'),
                ),
              ),
              child: const Text('Press me'),
            ),
          ),
          Story(
            name: 'Text',
            builder: (context) => Text(
              context.knobs.text(label: 'Text', initial: 'Simple text story'),
            ),
          ),
          Story(
            name: 'Scaffold',
            builder: (context) => Scaffold(
              appBar: AppBar(
                title: const Text('Storybook'),
              ),
              body: const Center(child: Text('Hello World!')),
            ),
          ),
          Story(
            name: 'Counter',
            builder: (context) => CounterPage(
              title: context.knobs.text(label: 'Title', initial: 'Counter'),
              enabled: context.knobs.boolean(label: 'Enabled', initial: true),
            ),
          ),
        ],
      );
}

class CounterPage extends StatefulWidget {
  const CounterPage({
    Key? key,
    required this.title,
    this.enabled = true,
  }) : super(key: key);

  final String title;
  final bool enabled;

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

class _CounterPageState extends State<CounterPage> {
  int _counter = 0;

  void _incrementCounter() => setState(() => _counter++);

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          actions: [
            IconButton(
              icon: const Icon(Icons.help),
              onPressed: () => showAboutDialog(
                context: context,
                applicationName: 'Storybook',
                applicationVersion: '0.0.1',
                applicationIcon: const Icon(Icons.book),
                applicationLegalese: 'MIT License',
              ),
            ),
          ],
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text('You have pushed the button this many times:'),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
        floatingActionButton: widget.enabled
            ? FloatingActionButton(
                onPressed: _incrementCounter,
                tooltip: 'Increment',
                child: const Icon(Icons.add),
              )
            : null,
      );
}
317
likes
0
pub points
94%
popularity

Publisher

verified publisherookamikb.dev

A storybook for Flutter widgets. Live preview of isolated widgets for faster development and showcase.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, device_frame, flutter, freezed_annotation, nested, provider, recase

More

Packages that depend on storybook_flutter