shake_widget_flutter 0.0.2
shake_widget_flutter: ^0.0.2 copied to clipboard
A simple Flutter widget that adds shake animation to any widget. Perfect for indicating errors, drawing attention, or playful effects.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:shake_widget_flutter/shake_widget_flutter.dart';
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: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
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 GlobalKey<ShakeWidgetState> keyShake = GlobalKey<ShakeWidgetState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ShakeAnimatedWidget(
key: keyShake,
shakeCount: 3,
shakeOffset: 10,
shakeDuration: const Duration(milliseconds: 500),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
),
),
ElevatedButton(
onPressed: () {
keyShake.currentState?.shake();
},
child: Text("Shake"),
),
],
),
),
);
}
}