state_illustrator 2.0.0 copy "state_illustrator: ^2.0.0" to clipboard
state_illustrator: ^2.0.0 copied to clipboard

A Flutter package for creating and visualizing custom state illustrations.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'StateIllustrator Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'StateIllustrator Demo'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  ViewState _state = ViewState.loading;

  void _setState(ViewState newState) {
    setState(() {
      _state = newState;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Column(
        children: [
          // Expanded to fill screen with StateIllustrator
          Expanded(
            child: StateIllustrator(
              state: _state,
              onRetry: () => _setState(ViewState.loading),
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: const [
                    Text(
                      'Data Loaded Successfully!',
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),

          // Buttons to switch states
          Padding(
            padding: const EdgeInsets.all(16),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                ElevatedButton(
                  onPressed: () => _setState(ViewState.loading),
                  child: const Text('Loading'),
                ),
                ElevatedButton(
                  onPressed: () => _setState(ViewState.empty),
                  child: const Text('Empty'),
                ),
                ElevatedButton(
                  onPressed: () => _setState(ViewState.error),
                  child: const Text('Error'),
                ),
              ],
            ),
          ),
          SizedBox(height: 30,),
        ],
      ),
    );
  }
}
1
likes
160
points
145
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for creating and visualizing custom state illustrations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_svg, lottie

More

Packages that depend on state_illustrator