wx_icon 1.2.0
wx_icon: ^1.2.0 copied to clipboard
Bring icons to life with fluid animations, seamless state transitions.
import 'package:flutter/material.dart';
import 'package:wx_icon/wx_icon.dart';
import 'package:choice/choice.dart';
import 'package:animated_checkmark/animated_checkmark.dart';
import 'package:wx_text/wx_text.dart';
import 'dart:math';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Widgetarian Icon',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: false,
),
home: const MyHomePage(title: 'Widgetarian Icon'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _random = Random();
final _icons = [
Icons.star,
Icons.favorite,
Icons.bookmark,
];
int _icon = 0;
Color? _color;
double _opacity = 1.0;
double _size = 64;
double _rotate = 0;
double _scale = 1;
bool _flipX = false;
bool _flipY = false;
void changeIcon() {
final maxIndex = _icons.length;
int randomIndex;
do {
randomIndex = 0 + _random.nextInt(maxIndex - 0);
} while (_icon == randomIndex);
setState(() {
_icon = randomIndex;
});
}
void setColor(Color color) {
setState(() => _color = color);
}
void setOpacity(double opacity) {
setState(() => _opacity = opacity);
}
void setSize(double size) {
setState(() => _size = size);
}
void _increaseRotate() {
setState(() {
_rotate += 45;
});
}
void _decreaseRotate() {
setState(() {
_rotate -= 45;
});
}
void _increaseScale() {
setState(() {
_scale += .5;
});
}
void _decreaseScale() {
setState(() {
_scale -= .5;
});
}
void _toggleFlipX() {
setState(() {
_flipX = !_flipX;
});
}
void _toggleFlipY() {
setState(() {
_flipY = !_flipY;
});
}
@override
Widget build(BuildContext context) {
return Wrapper(
children: [
Example(
title: 'WxIcon',
child: Column(
children: <Widget>[
InkWell(
onTap: changeIcon,
child: WxIcon(
_icons[_icon],
color: _color,
opacity: _opacity,
size: _size,
scale: _scale,
rotate: _rotate,
flipX: _flipX,
flipY: _flipY,
),
),
const SizedBox(height: 20),
SizedBox(
width: 250,
child: Slider(
value: _size,
max: 200,
min: 10,
label: _size.round().toString(),
onChanged: setSize,
),
),
SizedBox(
width: 250,
child: Slider(
value: _opacity,
max: 1,
min: 0,
label: _opacity.round().toString(),
onChanged: setOpacity,
),
),
const SizedBox(height: 10),
Wrap(
spacing: 10,
children: [
InkResponse(
radius: 24,
onTap: _decreaseRotate,
child: const Icon(Icons.rotate_left),
),
InkResponse(
radius: 24,
onTap: _decreaseScale,
child: const Icon(Icons.keyboard_double_arrow_down),
),
InkResponse(
radius: 24,
onTap: _toggleFlipX,
child: const Icon(Icons.compare_arrows),
),
RotatedBox(
quarterTurns: 1,
child: InkResponse(
radius: 24,
onTap: _toggleFlipY,
child: const Icon(Icons.compare_arrows),
),
),
InkResponse(
radius: 24,
onTap: _increaseScale,
child: const Icon(Icons.keyboard_double_arrow_up),
),
InkResponse(
radius: 24,
onTap: _increaseRotate,
child: const Icon(Icons.rotate_right),
),
],
),
const SizedBox(height: 15),
Container(
alignment: Alignment.center,
child: GridView.builder(
shrinkWrap: true,
itemCount: Colors.primaries.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisSpacing: 2,
crossAxisSpacing: 2,
crossAxisCount: 9,
),
itemBuilder: (_, i) {
final color = Colors.primaries[i];
return Card(
color: color,
child: InkWell(
onTap: () => setColor(color),
child: AnimatedCheckmark(
weight: 4,
color: Colors.white70,
value: _color == color,
),
),
);
},
),
),
],
),
),
Example(
title: 'WxToggleIcon',
child: Choice(
multiple: true,
clearable: true,
builder: (choice, child) {
return Wrap(
spacing: 15,
runSpacing: 15,
children: [
IconButton(
iconSize: 32,
onPressed: () => choice.select('bookmark'),
icon: WxToggleIcon(
Icons.bookmark,
baseIcon: Icons.bookmark_border,
selected: choice.selected('bookmark'),
size: 32,
),
),
IconButton(
iconSize: 32,
onPressed: () => choice.select('favorite'),
icon: WxToggleIcon.scaleUp(
Icons.favorite,
baseIcon: Icons.favorite_border,
selected: choice.selected('favorite'),
size: 32,
),
),
IconButton(
iconSize: 32,
onPressed: () => choice.select('star'),
icon: WxToggleIcon.scaleDown(
Icons.star,
selected: choice.selected('star'),
size: 32,
rotate: 45,
selectedStyle: const WxToggleIconStyle(
rotate: 0,
),
),
),
IconButton(
iconSize: 32,
onPressed: () => choice.select('tree'),
icon: WxToggleIcon(
Icons.account_tree,
baseIcon: Icons.account_tree_outlined,
selected: choice.selected('tree'),
size: 32,
color: Colors.orange,
),
),
],
);
},
),
)
],
);
}
}
class Wrapper extends StatelessWidget {
const Wrapper({
super.key,
required this.children,
});
final List<Widget> children;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 300,
),
child: Column(
children: children,
),
),
),
),
);
}
}
class Example extends StatelessWidget {
const Example({
super.key,
required this.title,
required this.child,
});
final String title;
final Widget child;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 5),
child: Center(
child: WxText.headlineSmall(
title,
gradient: const LinearGradient(
colors: [
Colors.green,
Colors.blue,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
fontWeight: FontWeight.bold,
),
),
),
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: SizedBox(
width: double.infinity,
child: Center(child: child),
),
),
),
],
);
}
}