### FortuneBar Widget Example Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Renders a compact horizontal strip of items that scrolls left/right to land on the selected index. Ideal when vertical space is limited. Configure animation, styling, and item behavior. ```dart import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart'; class SpinBarPage extends StatefulWidget { @override _SpinBarPageState createState() => _SpinBarPageState(); } class _SpinBarPageState extends State { final StreamController _controller = StreamController(); bool _isAnimating = false; @override void dispose() { _controller.close(); super.dispose(); } void _roll() { _controller.add(Fortune.randomInt(0, 6)); } @override Widget build(BuildContext context) { return Scaffold( body: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ FortuneBar( height: 80.0, selected: _controller.stream, visibleItemCount: 3, fullWidth: true, rotationCount: 100, duration: Duration(seconds: 4), curve: FortuneCurve.spin, onAnimationStart: () => setState(() => _isAnimating = true), onAnimationEnd: () => setState(() => _isAnimating = false), onFling: _roll, styleStrategy: AlternatingStyleStrategy(), items: [ FortuneItem(child: Text('🎁 Bonus'), weight: 1), FortuneItem(child: Text('💎 Diamond'), weight: 2), FortuneItem(child: Text('⭐ Star'), weight: 1), FortuneItem(child: Text('🚀 Rocket'), weight: 3), FortuneItem(child: Text('🍀 Clover'), weight: 1), FortuneItem(child: Text('❌ Miss'), weight: 2), ], ), SizedBox(height: 24), ElevatedButton( onPressed: _isAnimating ? null : _roll, child: Text('Roll'), ), ], ), ); } } ``` -------------------------------- ### Implement a FortuneWheel for Spinning Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt This example demonstrates how to create a basic spinning fortune wheel. It uses a `StreamController` to manage the selected item index and includes configurations for animation, haptics, and item styling. Ensure you have at least two `FortuneItem` widgets. ```dart import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart'; class SpinWheelPage extends StatefulWidget { @override _SpinWheelPageState createState() => _SpinWheelPageState(); } class _SpinWheelPageState extends State { final StreamController _controller = StreamController(); bool _isAnimating = false; @override void dispose() { _controller.close(); super.dispose(); } void _spin() { // Pick a random item index _controller.add(Fortune.randomInt(0, 5)); } @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Expanded( child: FortuneWheel( selected: _controller.stream, // Animate 100 full rotations over 5 seconds before settling rotationCount: 100, duration: Duration(seconds: 5), curve: FortuneCurve.spin, alignment: Alignment.topCenter, hapticImpact: HapticImpact.medium, onAnimationStart: () => setState(() => _isAnimating = true), onAnimationEnd: () => setState(() => _isAnimating = false), onFling: _spin, // Triggered when user flings the wheel onFocusItemChanged: (index) => debugPrint('Focused: $index'), indicators: [ FortuneIndicator( alignment: Alignment.topCenter, child: TriangleIndicator( color: Colors.red, width: 30, height: 30, elevation: 3, ), ), ], items: [ FortuneItem(child: Text('Gold'), style: FortuneItemStyle(color: Colors.amber)), FortuneItem(child: Text('Silver'), style: FortuneItemStyle(color: Colors.grey)), FortuneItem(child: Text('Bronze'), style: FortuneItemStyle(color: Colors.brown)), FortuneItem(child: Text('Prize'), style: FortuneItemStyle(color: Colors.green)), FortuneItem(child: Text('Retry'), style: FortuneItemStyle(color: Colors.red)), ], ), ), ElevatedButton( onPressed: _isAnimating ? null : _spin, child: Text('Spin'), ), ], ), ); } } ``` -------------------------------- ### FortuneItemStyle Examples Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Defines the visual appearance of FortuneItems, including solid colors, gradients, borders, and text styles. Can also create disabled styles based on theme. ```dart // Solid color style const solidStyle = FortuneItemStyle( color: Colors.teal, borderColor: Colors.tealAccent, borderWidth: 2.0, textAlign: TextAlign.center, textStyle: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w600), ); // Gradient style (overrides color when set) const gradientStyle = FortuneItemStyle( gradient: LinearGradient( colors: [Colors.pink, Colors.deepPurple], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderColor: Colors.white, borderWidth: 1.5, ); // Disabled style derived from theme Widget build(BuildContext context) { final disabledStyle = FortuneItemStyle.disabled( Theme.of(context), opacity: 0.2, ); return FortuneWheel( selected: Stream.value(0), items: [ FortuneItem(child: Text('Active'), style: solidStyle), FortuneItem(child: Text('Gradient'), style: gradientStyle), FortuneItem(child: Text('Disabled'), style: disabledStyle), ], ); } ``` -------------------------------- ### Customize Fortune Wheel Indicators Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Customize the position indicators of a FortuneWheel by providing a list of `FortuneIndicator` widgets to the `indicators` property. This example shows a customized `TriangleIndicator` with changed color, size, and alignment. ```dart FortuneWheel( selected: Stream.value(0), indicators: [ FortuneIndicator( alignment: Alignment.bottomCenter, // <-- changing the position of the indicator child: TriangleIndicator( color: Colors.green, // <-- changing the color of the indicator width: 20.0, // <-- changing the width of the indicator height: 20.0, // <-- changing the height of the indicator elevation: 0, // <-- changing the elevation of the indicator ), ), ], items: [ FortuneItem(child: Text('A')) FortuneItem(child: Text('B')), ], ) ``` -------------------------------- ### Basic FortuneWheel Usage Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Import and use the FortuneWheel widget. Requires a StreamController to manage selections. ```dart import 'package:flutter/material.dart'; import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart'; StreamController controller = StreamController(); FortuneWheel( selected: controller.stream, items: [ FortuneItem(child: Text('Han Solo')), FortuneItem(child: Text('Yoda')), FortuneItem(child: Text('Obi-Wan Kenobi')), ], ) ``` -------------------------------- ### FortuneBar with UniformStyleStrategy and Custom Appearance Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Employ UniformStyleStrategy for FortuneBar to ensure all items share a consistent style. Customize color, borders, text alignment, and text style. Use disabledIndices to grey out specific items. ```dart FortuneBar( selected: Stream.value(0), styleStrategy: UniformStyleStrategy( color: Colors.indigo.shade200, borderColor: Colors.indigo, borderWidth: 3.0, textAlign: TextAlign.center, textStyle: TextStyle(color: Colors.white, fontWeight: FontWeight.bold), disabledIndices: [2], ), items: [ FortuneItem(child: Text('One')), FortuneItem(child: Text('Two')), FortuneItem(child: Text('Three')), // greyed out ], ) ``` -------------------------------- ### Basic FortuneBar Usage Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Use the FortuneBar widget as an alternative to FortuneWheel, suitable for vertical screen space constraints. Requires a StreamController for selections. ```dart import 'package:flutter/material.dart'; import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart'; StreamController controller = StreamController(); FortuneBar( selected: controller.stream, items: [ FortuneItem(child: Text('Han Solo')), FortuneItem(child: Text('Yoda')), FortuneItem(child: Text('Obi-Wan Kenobi')), ], ) ``` -------------------------------- ### FortuneItem with Custom Styles and Weights Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Defines individual items for Fortune Widgets, supporting custom weights for size, styles for appearance, and gesture callbacks. Use this to create diverse and interactive items. ```dart // Items with custom weights, styles, and tap handlers List items = [ FortuneItem( child: Text('Jackpot', style: TextStyle(fontWeight: FontWeight.bold)), weight: 1.0, // smallest slice style: FortuneItemStyle( color: Colors.yellow, borderColor: Colors.orange, borderWidth: 3.0, textAlign: TextAlign.center, textStyle: TextStyle(color: Colors.black, fontSize: 16), ), onTap: () => debugPrint('Jackpot tapped!'), onLongPress: () => debugPrint('Jackpot long-pressed!'), ), FortuneItem( child: Text('Double'), weight: 2.0, // twice as wide/large as weight-1 items style: FortuneItemStyle( gradient: LinearGradient(colors: [Colors.blue, Colors.purple]), borderColor: Colors.white, borderWidth: 2.0, ), ), FortuneItem( child: Icon(Icons.star, color: Colors.white), weight: 3.0, // largest slice style: FortuneItemStyle(color: Colors.red), onDoubleTap: () => debugPrint('Star double-tapped!'), ), ]; // Use the items in a FortuneWheel FortuneWheel( selected: Stream.value(0), items: items, ) ``` -------------------------------- ### FortuneWheel with CircularPanPhysics and Fling-to-Spin Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Configure CircularPanPhysics for FortuneWheel to control rotational drag gestures. Set allowOppositeRotationFlung to false to restrict flings to the natural direction of rotation. Use onFling to trigger spin actions. ```dart StreamController controller = StreamController(); FortuneWheel( selected: controller.stream, physics: CircularPanPhysics( duration: Duration(milliseconds: 500), curve: Curves.decelerate, allowOppositeRotationFlung: false, // only allow natural-direction flings ), onFling: () => controller.add(Fortune.randomInt(0, 4)), items: [ FortuneItem(child: Text('North')), FortuneItem(child: Text('East')), FortuneItem(child: Text('South')), FortuneItem(child: Text('West')), ], ) ``` -------------------------------- ### Common Styling for FortuneWidget Items Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Apply common styling logic to all items in a FortuneWidget by passing a `StyleStrategy` to the `styleStrategy` property. The `AlternatingStyleStrategy` is used here for a FortuneBar. ```dart FortuneBar( // using alternating item styles on a fortune bar styleStrategy: AlternatingStyleStrategy(), selected: Stream.value(0), items: [ FortuneItem(child: Text('Han Solo')), FortuneItem(child: Text('Yoda')), FortuneItem(child: Text('Obi-Wan Kenobi')), ], ) ``` -------------------------------- ### HapticImpact for Device Feedback on Slice Crossing Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Configure HapticImpact on FortuneWheel to trigger device haptic feedback when the wheel crosses a slice boundary during animation. Options include none, light, medium, and heavy. ```dart StreamController controller = StreamController(); FortuneWheel( selected: controller.stream, hapticImpact: HapticImpact.heavy, // strong vibration on each slice crossing onFling: () => controller.add(Fortune.randomInt(0, 5)), items: [ FortuneItem(child: Text('🎯')), FortuneItem(child: Text('🏆')), FortuneItem(child: Text('💰')), FortuneItem(child: Text('🎁')), FortuneItem(child: Text('❌')), ], ) ``` -------------------------------- ### Customizing FortuneWheel Physics and Fling Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Customize the drag behavior and animation curve of the FortuneWheel using CircularPanPhysics. The onFling callback can be used to trigger new selections. ```dart StreamController controller = StreamController(); FortuneWheel( // changing the return animation when the user stops dragging physics: CircularPanPhysics( duration: Duration(seconds: 1), curve: Curves.decelerate, ), onFling: () { controller.add(1); } selected: controller.stream, items: [ FortuneItem(child: Text('Han Solo')), FortuneItem(child: Text('Yoda')), FortuneItem(child: Text('Obi-Wan Kenobi')), ], ) ``` -------------------------------- ### FortuneBar with Vertical DirectionalPanPhysics Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Implement DirectionalPanPhysics.vertical for FortuneBar to enable vertical drag gestures. Customize the animation duration and curve. ```dart FortuneBar( selected: Stream.value(0), physics: DirectionalPanPhysics.vertical( duration: Duration(milliseconds: 400), curve: Curves.easeOut, ), items: [ FortuneItem(child: Text('Item 1')), FortuneItem(child: Text('Item 2')), FortuneItem(child: Text('Item 3')), ], ) ``` -------------------------------- ### Style FortuneItems Individually Source: https://github.com/kevlatus/flutter_fortune_wheel/blob/main/README.md Use the `style` property of FortuneItem to apply custom colors, border widths, and border colors to individual slices. Other items will use default styling. ```dart FortuneWheel( selected: Stream.value(0), items: [ FortuneItem( child: Text('A'), style: FortuneItemStyle( color: Colors.red, // <-- custom circle slice fill color borderColor: Colors.green, // <-- custom circle slice stroke color borderWidth: 3, // <-- custom circle slice stroke width ), ), FortuneItem(child: Text('B')), ], ) ``` -------------------------------- ### FortuneWheel with AlternatingStyleStrategy and Disabled Indices Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Use AlternatingStyleStrategy for FortuneWheel to apply alternating opacities to items. Specify disabledIndices to visually grey out specific items. ```dart FortuneWheel( selected: Stream.value(0), styleStrategy: AlternatingStyleStrategy( disabledIndices: [1, 3], // items at index 1 and 3 appear greyed out ), items: [ FortuneItem(child: Text('A')), // enabled, full opacity FortuneItem(child: Text('B')), // disabled, greyed out FortuneItem(child: Text('C')), // enabled, half opacity (even alternation) FortuneItem(child: Text('D')), // disabled, greyed out FortuneItem(child: Text('E')), // enabled, full opacity ], ) ``` -------------------------------- ### Fortune Utility Methods for Randomness and Indefinite Spinning Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Use Fortune utility methods to pick random items, indices, or durations. The Fortune.indefinite sentinel value is used with a StreamController for continuous spinning until a definitive index is provided. ```dart int randomIndex = Fortune.randomInt(0, items.length); ``` ```dart String prize = Fortune.randomItem(['Gold', 'Silver', 'Bronze']); ``` ```dart Duration duration = Fortune.randomDuration( Duration(seconds: 3), Duration(seconds: 8), ); ``` ```dart StreamController controller = StreamController(); FortuneWheel( selected: controller.stream, items: [ FortuneItem(child: Text('A')), FortuneItem(child: Text('B')), FortuneItem(child: Text('C')), ], ) ``` ```dart controller.add(Fortune.indefinite); ``` ```dart await Future.delayed(Duration(seconds: 3)); controller.add(Fortune.randomInt(0, 3)); // wheel decelerates and lands on this index ``` -------------------------------- ### FortuneCurve for Spin Animation Transitions Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Utilize FortuneCurve for predefined animation curves. FortuneCurve.spin provides a default smooth deceleration, while FortuneCurve.none instantly snaps to the selected item. Custom Flutter curves can also be applied. ```dart FortuneWheel( selected: Stream.value(2), curve: FortuneCurve.spin, items: [ FortuneItem(child: Text('A')), FortuneItem(child: Text('B')), FortuneItem(child: Text('C')), ], ) ``` ```dart FortuneWheel( selected: Stream.value(0), curve: FortuneCurve.none, animateFirst: false, // also suppress the initial animation on first build items: [ FortuneItem(child: Text('X')), FortuneItem(child: Text('Y')), FortuneItem(child: Text('Z')), ], ) ``` ```dart FortuneBar( selected: Stream.value(1), curve: Curves.bounceOut, duration: Duration(seconds: 3), items: [ FortuneItem(child: Text('Bounce')), FortuneItem(child: Text('Landing')), FortuneItem(child: Text('Here')), ], ) ``` -------------------------------- ### FortuneBar with NoPanPhysics to Disable Drag Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Apply NoPanPhysics to a FortuneBar to completely disable user drag interactions, making the widget static. ```dart FortuneBar( selected: Stream.value(0), physics: NoPanPhysics(), items: [ FortuneItem(child: Text('Fixed')), FortuneItem(child: Text('Bar')), FortuneItem(child: Text('Only')), ], ) ``` -------------------------------- ### FortuneWheel with Custom Triangle Indicators Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Add multiple FortuneIndicator widgets to a FortuneWheel to display custom indicators at different positions. TriangleIndicator is commonly used for FortuneWheel. ```dart FortuneWheel( selected: Stream.value(0), indicators: [ // Primary indicator at top center (default position) FortuneIndicator( alignment: Alignment.topCenter, child: TriangleIndicator( color: Colors.red, width: 24.0, height: 24.0, elevation: 4, ), ), // Secondary indicator at bottom center FortuneIndicator( alignment: Alignment.bottomCenter, child: TriangleIndicator( color: Colors.blue, width: 16.0, height: 16.0, elevation: 0, ), ), ], items: [ FortuneItem(child: Text('A')), FortuneItem(child: Text('B')), FortuneItem(child: Text('C')), ], ) ``` -------------------------------- ### FortuneBar with Custom Rectangle Indicator Source: https://context7.com/kevlatus/flutter_fortune_wheel/llms.txt Utilize FortuneIndicator with RectangleIndicator for FortuneBar to create a custom frame around the center slot. Customize border and background color. ```dart FortuneBar( selected: Stream.value(1), indicators: [ FortuneIndicator( alignment: Alignment.topCenter, child: RectangleIndicator( borderColor: Colors.orange, borderWidth: 4.0, color: Colors.orange.withOpacity(0.1), ), ), ], items: [ FortuneItem(child: Text('X')), FortuneItem(child: Text('Y')), FortuneItem(child: Text('Z')), ], ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.