blurhash_ffi 1.1.0 copy "blurhash_ffi: ^1.1.0" to clipboard
blurhash_ffi: ^1.1.0 copied to clipboard

A compact, fast and easy to use blurry image placeholder generator for Flutter using native ffi bindings.

example/lib/main.dart

import 'package:blurhash_ffi/blurhash_the_image.dart';
import 'package:flutter/material.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int selectedImage = -1;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Blurhash FFI Example'),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [1, 2, 3].map<Widget>((e) {
                    var assetName = e == 2
                        ? 'assets/images/$e.png'
                        : 'assets/images/$e.jpg';
                    return MaterialButton(
                      padding: EdgeInsets.zero,
                      onPressed: () async {
                        setState(() {
                          selectedImage = e;
                        });
                      },
                      child: ImageSelect(
                        imageProvider: AssetImage(assetName),
                        isSelected: selectedImage == e,
                      ),
                    );
                  }).toList(),
                ),
                if (selectedImage != -1)
                  Align(
                    alignment: Alignment.center,
                    child: SizedBox(
                      height: 120,
                      width: 120,
                      child: Image(
                        image: BlurhashTheImage(
                          AssetImage(
                              selectedImage == 2 ? 'assets/images/$selectedImage.png' :
                              'assets/images/$selectedImage.jpg'),
                          decodingWidth: 120,
                          decodingHeight: 120,
                        ),
                        loadingBuilder: (context, child, loadingProgress) => loadingProgress == null
                            ? child
                            : const Center(
                                child: CircularProgressIndicator(
                                  color: Color(0xFFF1D4D4),
                                ),
                              ),
                        frameBuilder: (context, child, frame, wasSynchronouslyLoaded) => child,
                      ) 
                    ),
                  )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class ImageSelect extends StatelessWidget {
  final ImageProvider imageProvider;
  final bool isSelected;
  const ImageSelect(
      {super.key, required this.imageProvider, this.isSelected = false});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(
        decoration: BoxDecoration(
          border: isSelected ? Border.all(color: Colors.blue, width: 2) : null,
        ),
        child: Image(
          image: imageProvider,
          width: 100,
          height: 100,
        ),
      ),
    );
  }
}
92
likes
0
points
3.06k
downloads

Publisher

verified publisherfolksable.com

Weekly Downloads

A compact, fast and easy to use blurry image placeholder generator for Flutter using native ffi bindings.

Repository (GitHub)
View/report issues

Topics

#blurhash #ffi #images

License

unknown (license)

Dependencies

ffi, flutter, logging

More

Packages that depend on blurhash_ffi