banner_package 0.0.5 copy "banner_package: ^0.0.5" to clipboard
banner_package: ^0.0.5 copied to clipboard

A customizable Flutter banner package for promotions, ads, and call-to-action displays with animations, themes, and extensive customization options.

example/main.dart

import 'package:flutter/material.dart';
import 'package:banner_package/banner_package.dart';

void main() {
  runApp(const BannerExampleApp());
}

class BannerExampleApp extends StatelessWidget {
  const BannerExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Banner Package Demo',
      theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
      home: const BannerDemoScreen(),
    );
  }
}

class BannerDemoScreen extends StatefulWidget {
  const BannerDemoScreen({Key? key}) : super(key: key);

  @override
  State<BannerDemoScreen> createState() => _BannerDemoScreenState();
}

class _BannerDemoScreenState extends State<BannerDemoScreen> {
  bool _showPromotionalBanner = false;
  bool _showAdBanner = false;
  bool _showCallToActionBanner = false;
  bool _showBackgroundImageBanner = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Banner Package Demo'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Stack(
        children: [
          // Main content
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const Text(
                  'Banner Package Demo',
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 16),
                const Text(
                  'Tap the buttons below to show different types of banners:',
                  style: TextStyle(fontSize: 16),
                ),
                const SizedBox(height: 24),

                // Promotional Banner Button
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton.icon(
                    onPressed: () {
                      setState(() {
                        _showPromotionalBanner = true;
                      });
                    },
                    icon: const Icon(Icons.campaign),
                    label: const Text('Show Promotional Banner'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFF6C63FF),
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.all(16),
                    ),
                  ),
                ),
                const SizedBox(height: 12),

                // Ad Banner Button
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton.icon(
                    onPressed: () {
                      setState(() {
                        _showAdBanner = true;
                      });
                    },
                    icon: const Icon(Icons.shopping_cart),
                    label: const Text('Show Advertisement Banner'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFF00C9A7),
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.all(16),
                    ),
                  ),
                ),
                const SizedBox(height: 12),

                // Call to Action Banner Button
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton.icon(
                    onPressed: () {
                      setState(() {
                        _showCallToActionBanner = true;
                      });
                    },
                    icon: const Icon(Icons.star),
                    label: const Text('Show Call to Action Banner'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFFFF6B6B),
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.all(16),
                    ),
                  ),
                ),

                const SizedBox(height: 12),

                // Background Image Banner Button
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton.icon(
                    onPressed: () {
                      setState(() {
                        _showBackgroundImageBanner = true;
                      });
                    },
                    icon: const Icon(Icons.image),
                    label: const Text('Show Background Image Banner'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFF4ECDC4),
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.all(16),
                    ),
                  ),
                ),

                const SizedBox(height: 32),
                const Divider(),
                const SizedBox(height: 16),

                const Text(
                  'Features:',
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 8),
                const Text('✓ Customizable colors and gradients'),
                const Text('✓ Multiple animation types'),
                const Text('✓ Configurable sizes and positions'),
                const Text('✓ Auto-dismiss functionality'),
                const Text('✓ Swipe to dismiss'),
                const Text('✓ Icon and image support'),
                const Text('✓ Responsive design'),
                const Text('✓ Theme support'),
              ],
            ),
          ),

          // Promotional Banner
          if (_showPromotionalBanner)
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: PromotionalBanner(
                title: '🎉 Special Offer!',
                subtitle: 'Get 50% off on all premium features',
                buttonText: 'Claim Now',
                icon: Icons.local_offer,
                position: BannerPosition.top,
                animation: BannerAnimation.slideFromTop,
                bannerType: BannerType.promotional,
                autoDismissDuration: const Duration(seconds: 10),
                onButtonPressed: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Promotional offer claimed!')),
                  );
                },
                onDismiss: () {
                  setState(() {
                    _showPromotionalBanner = false;
                  });
                },
              ),
            ),

          // Ad Banner
          if (_showAdBanner)
            Positioned(
              top: 100,
              left: 0,
              right: 0,
              child: AdBanner(
                title: 'Premium Headphones',
                description:
                    'High-quality wireless headphones with noise cancellation',
                price: '\$299.99',
                discount: '30% OFF',
                actionText: 'Buy Now',
                animation: BannerAnimation.fadeIn,
                autoDismissDuration: const Duration(seconds: 8),
                onActionPressed: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Added to cart!')),
                  );
                },
                onTap: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Product details opened!')),
                  );
                },
                onDismiss: () {
                  setState(() {
                    _showAdBanner = false;
                  });
                },
              ),
            ),

          // Call to Action Banner
          if (_showCallToActionBanner)
            Positioned(
              bottom: 0,
              left: 0,
              right: 0,
              child: CallToActionBanner(
                title: 'Don\'t miss out!',
                description: 'Limited time offer - only 24 hours left',
                primaryActionText: 'Get Started',
                secondaryActionText: 'Learn More',
                icon: Icons.access_time,
                position: BannerPosition.bottom,
                animation: BannerAnimation.slideFromBottom,
                urgencyLevel: 3,
                autoDismissDuration: const Duration(seconds: 12),
                onPrimaryAction: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Getting started!')),
                  );
                },
                onSecondaryAction: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Learning more...')),
                  );
                },
                onDismiss: () {
                  setState(() {
                    _showCallToActionBanner = false;
                  });
                },
              ),
            ),

          // Background Image Banner
          if (_showBackgroundImageBanner)
            Positioned(
              top: 200,
              left: 0,
              right: 0,
              child: PromotionalBanner(
                title: 'Summer Sale',
                subtitle: 'Get up to 50% off on all items',
                buttonText: 'Shop Now',
                backgroundImageUrl:
                    'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800',
                backgroundImageFit: BoxFit.cover,
                backgroundImageOverlay: 0.4,
                textColor: Colors.white,
                buttonColor: Colors.orange,
                position: BannerPosition.top,
                animation: BannerAnimation.slideFromTop,
                icon: Icons.shopping_bag,
                autoDismissDuration: const Duration(seconds: 8),
                onButtonPressed: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Opening shop...')),
                  );
                },
                onDismiss: () {
                  setState(() {
                    _showBackgroundImageBanner = false;
                  });
                },
              ),
            ),
        ],
      ),
    );
  }
}
3
likes
160
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

A customizable Flutter banner package for promotions, ads, and call-to-action displays with animations, themes, and extensive customization options.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on banner_package