flutter_fortune_wheel 0.5.0
flutter_fortune_wheel: ^0.5.0 copied to clipboard
Visualize (random) selection processes with widgets like a spinning wheel of fortune or a fortune bar.
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_fortune_wheel/flutter_fortune_wheel.dart';
void main() {
runApp(ExampleApp());
}
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Fortune Wheel Example',
home: ExamplePage(),
);
}
}
class ExamplePage extends StatefulWidget {
@override
_ExamplePageState createState() => _ExamplePageState();
}
class _ExamplePageState extends State<ExamplePage> {
StreamController<int> selected = StreamController<int>();
@override
void dispose() {
selected.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
final items = <String>[
'Grogu',
'Mace Windu',
'Obi-Wan Kenobi',
'Han Solo',
'Luke Skywalker',
'Darth Vader',
'Yoda',
'Ahsoka Tano',
];
return Scaffold(
appBar: AppBar(
title: Text('Flutter Fortune Wheel'),
),
body: GestureDetector(
onTap: () {
setState(() {
selected.add(
Random().nextInt(items.length),
);
});
},
child: Column(
children: [
Expanded(
child: FortuneWheel(
selected: selected.stream,
items: [
for (var it in items) FortuneItem(child: Text(it)),
],
),
),
],
),
),
);
}
}