### Pubspec.yaml Dependency Source: https://pub.dev/packages/flutter_animate/install This is an example of how the flutter_animate dependency will appear in your pubspec.yaml file after running `flutter pub add`. ```yaml dependencies: flutter_animate: ^4.5.2 ``` -------------------------------- ### Initialize Flutter Animate Example Application Source: https://pub.dev/packages/flutter_animate/example Sets up the main entry point for the demo application, including shader loading and the navigation structure for different animation views. ```dart import 'dart:ui'; import 'package:example/examples/everything_view.dart'; import 'package:flutter/material.dart'; import 'examples/adapter_view.dart'; import 'examples/info_view.dart'; import 'examples/playground_view.dart'; import 'examples/visual_view.dart'; void main() { runApp(const MyApp()); _loadShader(); // this is a touch hacky, but works for now. } Future _loadShader() async { return FragmentProgram.fromAsset('assets/shaders/shader.frag').then( (FragmentProgram prgm) { EverythingView.shader = prgm.fragmentShader(); }, onError: (Object error, StackTrace stackTrace) { FlutterError.reportError( FlutterErrorDetails(exception: error, stack: stackTrace)); }); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return const MaterialApp( title: 'Flutter Animate Demo', debugShowCheckedModeBanner: false, home: FlutterAnimateExample(), ); } } // this is a very quick and dirty example. class FlutterAnimateExample extends StatefulWidget { const FlutterAnimateExample({Key? key}) : super(key: key); static final List tabs = [ TabInfo(Icons.info_outline, (_) => InfoView(key: UniqueKey()), 'Info', 'Simple example of Widget & List animations.'), TabInfo(Icons.palette_outlined, (_) => VisualView(key: UniqueKey()), 'Visual', 'Visual effects like saturation, tint, & blur.'), TabInfo(Icons.format_list_bulleted, (_) => const AdapterView(), 'Adapters', 'Animations driven by scrolling & user input.'), TabInfo(Icons.grid_on_outlined, (_) => const EverythingView(), 'Kitchen Sink', 'Grid view of effects with default settings.'), TabInfo(Icons.science_outlined, (_) => PlaygroundView(key: UniqueKey()), 'Playground', 'A blank canvas for experimenting.'), ]; @override State createState() => _FlutterAnimateExampleState(); } class _FlutterAnimateExampleState extends State { int _viewIndex = 0; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color(0xFF404349), bottomNavigationBar: BottomNavigationBar( currentIndex: _viewIndex, selectedFontSize: 12, unselectedFontSize: 12, selectedItemColor: const Color(0xFF80DDFF), unselectedItemColor: const Color(0x998898A0), showSelectedLabels: false, showUnselectedLabels: false, type: BottomNavigationBarType.fixed, backgroundColor: const Color(0xFF2A2B2F), elevation: 0, onTap: (index) => setState(() => _viewIndex = index), items: [ for (final tab in FlutterAnimateExample.tabs) BottomNavigationBarItem( icon: Icon(tab.icon), label: tab.label, ) ], ), body: DefaultTextStyle( style: const TextStyle( color: Color(0xFFCCCDCF), fontSize: 14, height: 1.5, ), child: SafeArea( bottom: false, child: FlutterAnimateExample.tabs[_viewIndex].builder(context), ), ), ); } } class TabInfo { const TabInfo(this.icon, this.builder, this.label, this.description); final IconData icon; final WidgetBuilder builder; final String label; final String description; } ``` -------------------------------- ### Import flutter_animate Source: https://pub.dev/packages/flutter_animate/install Import the flutter_animate package into your Dart code to start using its animation features. ```dart import 'package:flutter_animate/flutter_animate.dart'; ``` -------------------------------- ### Configure Effect Begin and End Values Source: https://pub.dev/packages/flutter_animate Specify begin and end parameters to define the start and end states of an effect. ```dart // an opacity of 1 is "neutral" Text("Hello").animate().fade() // begin=0, end=1 Text("Hello").animate().fade(begin: 0.5) // end=1 Text("Hello").animate().fade(end: 0.5) // begin=1 ``` -------------------------------- ### Listen to Animation Value Source: https://pub.dev/packages/flutter_animate Use ListenEffect to register a callback that receives the animation's current value (0.0 to 1.0). This example prints the opacity value during a fade-in. ```dart Text("Hello").animate().fadeIn(curve: Curves.easeOutExpo) .listen(callback: (value) => print('current opacity: $value')) ``` -------------------------------- ### Add Callback Halfway Through Animation Source: https://pub.dev/packages/flutter_animate Use CallbackEffect to trigger a function at a specific point in an animation. This example adds a callback halfway through a fade-in effect. ```dart Text("Hello").animate().fadeIn(duration: 600.ms) .callback(duration: 300.ms, callback: (_) => print('halfway')) ``` -------------------------------- ### Animate Based on State Changes Source: https://pub.dev/packages/flutter_animate Set a target value on the Animate widget to make it react to state changes. This example fades and scales a button based on a boolean `_over` variable. ```dart MyButton().animate(target: _over ? 1 : 0) .fade(end: 0.8).scaleXY(end: 1.1) ``` -------------------------------- ### Configure Animation Delay and Looping Source: https://pub.dev/packages/flutter_animate Use the Animate delay parameter for initial delays and onPlay for controller callbacks like looping. ```dart Text("Hello").animate( delay: 1000.ms, // this delay only happens once at the very start onPlay: (controller) => controller.repeat(), // loop ).fadeIn(delay: 500.ms) // this delay happens at the start of each loop ``` -------------------------------- ### Apply Effects with Extension Method Source: https://pub.dev/packages/flutter_animate Use the .animate() extension method on any widget for a shorthand, chainable syntax. ```dart Text("Hello World!").animate().fade().scale() ``` -------------------------------- ### Configure Delay and Duration Source: https://pub.dev/packages/flutter_animate Control animation timing by specifying delay and duration parameters for individual effects. ```dart Text("Hello").animate() .fade(duration: 500.ms) .scale(delay: 500.ms) // runs after fade. ``` -------------------------------- ### Add flutter_animate Dependency Source: https://pub.dev/packages/flutter_animate/install Run this command in your terminal to add the flutter_animate package to your Flutter project. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add flutter_animate ``` -------------------------------- ### Animate Lists with AnimateList Source: https://pub.dev/packages/flutter_animate Use AnimateList or the .animate() extension on a list of widgets to apply staggered effects. ```dart Column(children: AnimateList( interval: 400.ms, effects: [FadeEffect(duration: 300.ms)], children: [Text("Hello"), Text("World"), Text("Goodbye")], )) ``` ```dart Column( children: [Text("Hello"), Text("World"), Text("Goodbye")] .animate(interval: 400.ms).fade(duration: 300.ms), ) ``` -------------------------------- ### Apply Shaders with ShaderEffect Source: https://pub.dev/packages/flutter_animate Integrate GLSL fragment shaders into the animation chain. ```dart myWidget.animate() .shader(duration: 2.seconds, shader: myShader) .fadeIn(duration: 300.ms) // shader can be combined with other effects ``` -------------------------------- ### Apply Effect Parameters Source: https://pub.dev/packages/flutter_animate Pass additional parameters to effects to customize their behavior. ```dart Text('Hello').animate().tint(color: Colors.purple) ``` -------------------------------- ### Handle Animation Events Source: https://pub.dev/packages/flutter_animate Use callbacks like onPlay to access the AnimationController for manual control. ```dart Text("Horrible Pulsing Text") .animate(onPlay: (controller) => controller.repeat(reverse: true)) .fadeOut(curve: Curves.easeInOut) ``` -------------------------------- ### Create Custom Effects with CustomEffect Source: https://pub.dev/packages/flutter_animate Implement custom animation logic using a builder function that receives the current animation value. ```dart Text("Hello World").animate().custom( duration: 300.ms, builder: (context, value, child) => Container( color: Color.lerp(Colors.red, Colors.blue, value), padding: EdgeInsets.all(8), child: child, // child is the Text widget being animated ) ) ``` ```dart Animate().custom( duration: 10.seconds, begin: 10, end: 0, builder: (_, value, __) => Text(value.round()), ).fadeOut() ``` -------------------------------- ### Missing Type Annotation in Adapter Source: https://pub.dev/packages/flutter_animate/score This code snippet highlights a missing type annotation in the `_tick` method within `lib/src/adapters/adapter.dart`. Ensure type annotations are present for static analysis. ```dart ╷ 84 │ void _tick(_) { │ ^ ╵ ``` -------------------------------- ### Apply Effects with Animate Widget Source: https://pub.dev/packages/flutter_animate Use the Animate widget to wrap a target widget and define a list of effects. ```dart Animate( effects: [FadeEffect(), ScaleEffect()], child: Text("Hello World!"), ) ``` -------------------------------- ### Swap Widgets with SwapEffect Source: https://pub.dev/packages/flutter_animate Replace the target widget at a specific time or reset animation sequences. ```dart Text("Before").animate() .swap(duration: 900.ms, builder: (_, __) => Text("After")) ``` ```dart text.animate().fadeOut(300.ms) // fade out & then... // swap in original widget & fade back in via a new Animate: .swap(builder: (_, child) => child.animate().fadeIn()) ``` -------------------------------- ### Inherit Animation Parameters Source: https://pub.dev/packages/flutter_animate Effects inherit duration and delay from previous effects if not explicitly defined. ```dart Text("Hello World!").animate() .fadeIn() // uses `Animate.defaultDuration` .scale() // inherits duration from fadeIn .move(delay: 300.ms, duration: 600.ms) // runs after the above w/new duration .blurXY() // inherits the delay & duration from move ``` -------------------------------- ### Missing Type Annotation in Animate Source: https://pub.dev/packages/flutter_animate/score This code snippet points out a missing type annotation for the `status` parameter in the `_handleAnimationStatus` method within `lib/src/animate.dart`. Add type annotations for better code clarity and static analysis. ```dart ╷ 369 │ void _handleAnimationStatus(status) { │ ^^^^^^ ╵ ``` -------------------------------- ### Sequence Effects with ThenEffect Source: https://pub.dev/packages/flutter_animate Use the then method to sequence effects relative to the end time of the previous effect. ```dart Text("Hello").animate() .fadeIn(duration: 600.ms) .then(delay: 200.ms) // baseline=800ms .slide() ``` -------------------------------- ### Toggle State with ToggleEffect Source: https://pub.dev/packages/flutter_animate Use ToggleEffect to switch between boolean states based on animation duration. ```dart Animate().toggle( duration: 2.seconds, builder: (_, value, __) => Text(value ? "Before" : "After"), ) ``` ```dart Animate().toggle( duration: 1.ms, builder: (_, value, __) => AnimatedContainer( duration: 1.seconds, color: value ? Colors.red : Colors.green, ), ) ``` -------------------------------- ### Reuse Immutable Effects Source: https://pub.dev/packages/flutter_animate Define global collections of immutable Effect instances to maintain consistency across a design system. ```dart MyGlobalEffects.transitionIn = [ FadeEffect(duration: 100.ms, curve: Curves.easeOut), ScaleEffect(begin: 0.8, curve: Curves.easeIn) ] // then: Text('Hello').animate(effects: MyGlobalEffects.transitionIn) ``` -------------------------------- ### Callback After Animation Completes Source: https://pub.dev/packages/flutter_animate CallbackEffect inherits duration and delay from previous effects. This snippet executes a callback once a scale animation is finished. ```dart Text("Hello").animate().scale(delay: 200.ms, duration: 400.ms) .callback(callback: (_) => print('scale is done')) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.