mirror of
https://github.com/flutter/samples.git
synced 2026-04-28 02:18:47 +00:00
Adds ai_recipe_generation sample (#2242)
Adding the demo app from my I/O talk. Because AI. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. --------- Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
This commit is contained in:
85
ai_recipe_generation/lib/widgets/add_image_widget.dart
Normal file
85
ai_recipe_generation/lib/widgets/add_image_widget.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
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.withOpacity(.7),
|
||||
// hovered
|
||||
(true, _) => MarketplaceTheme.secondary.withOpacity(.3),
|
||||
// base color
|
||||
(_, _) => MarketplaceTheme.secondary.withOpacity(.3),
|
||||
};
|
||||
}
|
||||
|
||||
@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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user