Flutter scratch widget
scratcher è un package per Flutter che ci permette di eseguire uno scratch su un widget per visualizzare quello che c'è sotto.
Ad esempio una immagine.
Non so quante volte vi capiterà di usarlo, ma è interessante e divertente.
Quindi vediamo un esempio.
Per installarlo:
flutter pub add scratcher
Qui sotto un esempio di codice:
import 'package:flutter/material.dart';
import 'package:scratcher/scratcher.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Test',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Test'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
children: [
const Text("Scratch!"),
const SizedBox(height: 20),
Scratcher(
brushSize: 50,
threshold: 50,
color: Colors.amber,
child: Container(
width: 500,
height: 500,
color: Colors.grey,
child: Image.network("https://picsum.photos/300"),
),
)
],
),
),
);
}
}
Enjoy!
dart flutter scratcher
Commentami!