flashing_widget 1.0.0
flashing_widget: ^1.0.0 copied to clipboard
A customizable Flutter widget that creates a flashing animation effect before executing a callback function.
import 'package:flutter/material.dart';
import 'package:flashing_widget/flashing_widget.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flashing Widget Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const ExampleScreen(),
);
}
}
class ExampleScreen extends StatefulWidget {
const ExampleScreen({Key? key}) : super(key: key);
@override
State<ExampleScreen> createState() => _ExampleScreenState();
}
class _ExampleScreenState extends State<ExampleScreen> {
String _message = 'Tap any widget below to see the flashing effect!';
int _counter = 0;
void _updateMessage(String message) {
setState(() {
_message = message;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flashing Widget Examples'),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(8),
),
child: Text(
_message,
style: const TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 20),
// Basic Example
FlashingWidget(
onTap: () {
_updateMessage('Basic flashing widget tapped!');
},
beforeFlashing: () {
_updateMessage('Starting basic flash...');
},
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(10),
),
child: const Text(
'Basic Flash Widget',
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
const SizedBox(height: 20),
// Custom Duration Example
FlashingWidget(
flashDuration: const Duration(milliseconds: 200),
flashCount: 3,
onTap: () {
_updateMessage('Slow flash widget tapped!');
},
beforeFlashing: () {
_updateMessage('Starting slow flash...');
},
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(10),
),
child: const Text(
'Slow Flash (3x)',
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
const SizedBox(height: 20),
// Counter Example
FlashingWidget(
flashDuration: const Duration(milliseconds: 50),
flashCount: 8,
onTap: () {
setState(() {
_counter++;
});
_updateMessage('Counter incremented to $_counter!');
},
beforeFlashing: () {
_updateMessage('Fast flashing counter...');
},
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(10),
),
child: Text(
'Counter: $_counter\n(Fast Flash)',
style: const TextStyle(color: Colors.white, fontSize: 18),
textAlign: TextAlign.center,
),
),
),
const SizedBox(height: 20),
// Button Example
FlashingWidget(
onTap: () {
_updateMessage('Button-style widget tapped!');
},
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
decoration: BoxDecoration(
color: Colors.purple,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'Flash Button',
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
),
const SizedBox(height: 40),
],
),
),
),
);
}
}