mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +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:
98
ai_recipe_generation/lib/widgets/icon_loading_indicator.dart
Normal file
98
ai_recipe_generation/lib/widgets/icon_loading_indicator.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:ai_recipe_generation/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class IconLoadingAnimator extends StatefulWidget {
|
||||
IconLoadingAnimator({
|
||||
super.key,
|
||||
required this.icons,
|
||||
this.animationDuration,
|
||||
this.millisecondsBetweenAnimations,
|
||||
});
|
||||
|
||||
final List<IconData> icons;
|
||||
final Duration? animationDuration;
|
||||
final int? millisecondsBetweenAnimations;
|
||||
final List<Color> colors = [
|
||||
MarketplaceTheme.primary,
|
||||
MarketplaceTheme.secondary,
|
||||
MarketplaceTheme.tertiary,
|
||||
MarketplaceTheme.scrim,
|
||||
Colors.black87,
|
||||
];
|
||||
|
||||
@override
|
||||
State<IconLoadingAnimator> createState() => _IconLoadingAnimatorState();
|
||||
}
|
||||
|
||||
var rand = Random();
|
||||
|
||||
class _IconLoadingAnimatorState extends State<IconLoadingAnimator> {
|
||||
late List<IconData> notYetSeenIcons;
|
||||
late IconData currentIcon;
|
||||
late Color currentColor;
|
||||
late Timer timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
notYetSeenIcons = widget.icons;
|
||||
|
||||
currentIcon =
|
||||
notYetSeenIcons.removeAt(rand.nextInt(notYetSeenIcons.length));
|
||||
currentColor = widget.colors[rand.nextInt(widget.colors.length)];
|
||||
|
||||
timer = Timer.periodic(
|
||||
Duration(milliseconds: widget.millisecondsBetweenAnimations ?? 1000),
|
||||
(timer) {
|
||||
nextIcon();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void nextIcon() {
|
||||
if (notYetSeenIcons.length == 1) notYetSeenIcons = widget.icons;
|
||||
setState(() {
|
||||
currentIcon =
|
||||
notYetSeenIcons.removeAt(rand.nextInt(notYetSeenIcons.length));
|
||||
currentColor = widget.colors[rand.nextInt(widget.colors.length)];
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
border: Border.all(
|
||||
color: MarketplaceTheme.focusedBorderColor,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: AnimatedSwitcher(
|
||||
duration: widget.animationDuration ?? const Duration(milliseconds: 200),
|
||||
transitionBuilder: (child, animation) {
|
||||
return ScaleTransition(
|
||||
scale: animation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Icon(
|
||||
size: 75,
|
||||
color: currentColor,
|
||||
key: Key(currentIcon.hashCode.toString()),
|
||||
currentIcon,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user