mirror of
https://github.com/flutter/samples.git
synced 2026-05-30 10:59:25 +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:
58
ai_recipe_generation/lib/widgets/star_rating.dart
Normal file
58
ai_recipe_generation/lib/widgets/star_rating.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
|
||||
typedef StarRatingCallback = void Function(int);
|
||||
|
||||
class StartRating extends StatefulWidget {
|
||||
const StartRating({
|
||||
super.key,
|
||||
required this.starColor,
|
||||
required this.onTap,
|
||||
this.initialRating = -1,
|
||||
});
|
||||
|
||||
final Color starColor;
|
||||
final int initialRating;
|
||||
|
||||
/// If [onTap] is not null, the stars are interactive
|
||||
final StarRatingCallback? onTap;
|
||||
|
||||
@override
|
||||
State<StartRating> createState() => _StartRatingState();
|
||||
}
|
||||
|
||||
class _StartRatingState extends State<StartRating> {
|
||||
late int selectedIdx;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
selectedIdx = widget.initialRating - 1;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
...List.generate(
|
||||
5,
|
||||
(index) => GestureDetector(
|
||||
onTap: widget.onTap != null
|
||||
? () {
|
||||
setState(() {
|
||||
selectedIdx = index;
|
||||
});
|
||||
widget.onTap!(index);
|
||||
}
|
||||
: null,
|
||||
child: Icon(
|
||||
Symbols.kid_star,
|
||||
color: widget.starColor,
|
||||
fill: selectedIdx >= index ? 1 : 0,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user