floodfill_span 0.0.1
floodfill_span: ^0.0.1 copied to clipboard
A flutter package implementing the floodfill algorithm using Span filling
import 'dart:typed_data';
import 'package:floodfill_span/floodfill_widget.dart';
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
import 'package:image_gallery_saver/image_gallery_saver.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ui.Image? _image;
List<Color> colors = [
Colors.black,
Colors.red,
Colors.green,
Colors.blue,
Colors.yellow,
Colors.purple,
Colors.orange,
];
Color selectedColor = Colors.black;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Drawing App'),
actions: [
IconButton(
icon: const Icon(Icons.save),
onPressed: () {
if (_image != null) {
saveImageToGallery(_image!);
}
},
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: FloodFillWidget(
newColor: selectedColor,
onImageChanged: (image) {
_image = image;
},
imageUrl: "https://sun9-77.userapi.com/impg/BiGYCxYxSuZgeILSzA0dtPcNC7935fdhpW36rg/e3jk6CqTwkw.jpg?size=1372x1372&quality=95&sign=2afb3d42765f8777879e06c314345303&type=album",
),
),
SizedBox(
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(
horizontal: 30.0,
),
itemCount: colors.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
selectedColor = colors[index];
});
},
child: Container(
width: 50,
decoration: BoxDecoration(
color: colors[index],
border: Border.all(
color: selectedColor == colors[index] ? Colors.white : Colors.transparent,
width: 2,
),
),
),
);
},
),
),
const SizedBox(
height: 50,
)
],
),
),
);
}
Future<void> saveImageToGallery(ui.Image image) async {
final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
final Uint8List pngBytes = byteData!.buffer.asUint8List();
await ImageGallerySaver.saveImage(
Uint8List.fromList(pngBytes),
quality: 100,
name: "painted_image",
);
}
}