hit_slop 1.0.0
hit_slop: ^1.0.0 copied to clipboard
HitSlop increases the hit box of widgets without affecting the surrounding layout.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:hit_slop/hit_slop.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Builder(
builder: (context) {
return Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Tap the icon'),
HitSlopBuilder(
slop: const EdgeInsets.all(8),
builder: (context, hitBox) => GestureDetector(
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Pressed'),
behavior: SnackBarBehavior.floating,
),
);
},
child: Container(
color: Colors.green.withOpacity(0.2),
child: hitBox,
),
),
child: const Icon(
Icons.add,
color: Colors.black,
size: 24,
),
),
],
),
);
},
),
),
);
}
}