1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/ai_recipe_generation/lib/widgets/add_image_widget.dart
2024-09-01 17:25:33 +10:00

86 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:material_symbols_icons/symbols.dart';
import '../theme.dart';
class AddImage extends StatefulWidget {
const AddImage({
super.key,
required this.onTap,
this.height = 100,
this.width = 100,
});
final VoidCallback onTap;
final double height;
final double width;
@override
State<AddImage> createState() => _AddImageState();
}
class _AddImageState extends State<AddImage> {
bool hovered = false;
bool tappedDown = false;
Color get buttonColor {
var state = (hovered, tappedDown);
return switch (state) {
// tapped down state
(_, true) => MarketplaceTheme.secondary.withAlpha(179),
// hovered
(true, _) => MarketplaceTheme.secondary.withAlpha(77),
// base color
(_, _) => MarketplaceTheme.secondary.withAlpha(77),
};
}
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (event) {
setState(() {
hovered = true;
});
},
onExit: (event) {
setState(() {
hovered = false;
});
},
child: GestureDetector(
onTapDown: (details) {
setState(() {
tappedDown = true;
});
},
onTapUp: (details) {
setState(() {
tappedDown = false;
});
widget.onTap();
},
child: SizedBox(
width: widget.width,
height: widget.height,
child: ClipRRect(
borderRadius:
BorderRadius.circular(MarketplaceTheme.defaultBorderRadius),
child: Container(
decoration: BoxDecoration(
color: buttonColor,
),
child: const Center(
child: Icon(
Symbols.add_photo_alternate_rounded,
size: 32,
),
),
),
),
),
),
);
}
}