FlutterFX Widgets

repository·main·Indexed 20 days ago

https://github.com/flutterfx/flutterfx_widgets

A library of reusable, animated visual effects for Flutter applications. Includes packages such as flutterfx_blur_fade for blur-to-sharp and fade-in transitions, flutterfx_bottom_sheet for animated bottom sheets with scale-and-slide entrances, flutterfx_orbit_blur for counter-rotating orbiting icons with frosted-glass effects, and flutterfx_scratch_to_reveal.

Tokens
12.8K
Snippets
49
Records
64
Agent score
71%

What's inside flutterfx_widgets

  1. Overview of FlutterFX

    main
    FlutterFX is a collection of animated effects built with Flutter. Each effect is designed to serve as a building block that can be integrated into your own Flutter projects. The library provides various animated components and visual effects to enhance user interfaces.
  2. Implement reactive configuration with OrbitConfig

    main

    The OrbitConfig class is a ChangeNotifier. You can use it with an AnimatedBuilder to allow runtime updates to the orbit's direction, duration, or path visibility without manual state management.

    final config = OrbitConfig(reverse: false, duration: 6.0);
    
    AnimatedBuilder(
      animation: config,
      builder: (context, _) => OrbitingIcons(
        reverse: config.reverse,
        duration: config.duration,
        showPaths: config.showPaths,
      ),
    )
    
    // Mutating the config triggers a rebuild
    config.duration = 4.0;
    config.reverse = !config.reverse;
  3. How BlurFade animation works

    main

    The animation uses Curves.easeOut across two overlapping phases to create a seamless transition:

    1. Opacity Phase (0% - 60% of duration): Fades the widget from 0 to 1.
    2. Blur Phase (40% - 100% of duration): Transitions the blur sigma from 10 to 0.

    Visibility Logic

    • isVisible: null (default): The animation plays forward automatically when the widget is first built.
    • isVisible: true: The animation plays forward.
    • isVisible: false: The animation reverses (fades out while increasing blur).
  4. How ScratchToReveal works

    main

    The widget operates using the following mechanism:

    1. A gradient image is rendered onto an offscreen canvas using the provided gradientColors.
    2. A CustomPainter draws that image on top of the child widget, using BlendMode.clear to erase the path as the user performs the scratch gesture.
    3. Once the bounding box of the scratch path covers the specified minScratchPercentage of the total area, a scale + wiggle animation plays and the onComplete callback is triggered.
  5. Quick Start with FlutterFX

    main

    To get started with FlutterFX locally, follow these steps:

    1. Clone the repository to your local machine.
    2. Run flutter pub get in the project root to install dependencies.
    3. Open the project in your preferred IDE (e.g., VS Code, Android Studio).
    4. Run the application on a connected device or simulator.
    flutter pub get
  6. Customize iOS Launch Screen Assets

    main

    To change the launch screen image for the iOS version of the example app, you can use one of two methods:

    1. Direct File Replacement: Replace the existing image files located in the packages/flutterfx_blur_fade/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.
    2. Xcode Interface:
      • Open the iOS workspace using the command: open ios/Runner.xcworkspace.
      • In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
      • Drag and drop your desired images into the asset catalog.
    open ios/Runner.xcworkspace
  7. Create a new FlutterFX widget package

    main

    Follow these steps to initialize a new widget package within the packages directory using the standard FlutterFX structure. Replace WIDGET_NAME with your desired widget name.

    1. Initialize directory structure: Create the necessary folders for source code, examples, and screenshots.
    2. Use blur_fade as a template: Copy the configuration and boilerplate files from the existing flutterfx_blur_fade package to ensure consistency in linting, licensing, and structure.
    3. Update configuration: Ensure pubspec.yaml and library exports reflect the new name.
    4. Add assets: Copy your showcase GIF into the screenshots/ directory.
    5. Generate platform support: Run flutter create . inside the example directory to ensure all platforms are supported.
    6. Test and Publish: Run the widget locally and use dart pub publish to release it.
    # Step 1: Create Package
    cd packages
    mkdir -p flutterfx_WIDGET_NAME/lib/src
    mkdir -p flutterfx_WIDGET_NAME/example/lib
    mkdir -p flutterfx_WIDGET_NAME/screenshots
    
    # Step 2: Copy Files from blur_fade as Template
    cp flutterfx_blur_fade/pubspec.yaml flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/README.md flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/CHANGELOG.md flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/LICENSE flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/analysis_options.yaml flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/.gitignore flutterfx_WIDGET_NAME/
    cp flutterfx_blur_fade/lib/flutterfx_blur_fade.dart flutterfx_WIDGET_NAME/lib/flutterfx_WIDGET_NAME.dart
    cp -r flutterfx_blur_fade/example/lib flutterfx_WIDGET_NAME/example/
    cp flutterfx_blur_fade/example/pubspec.yaml flutterfx_WIDGET_NAME/example/
    
    # Step 4: Add Screenshot
    cp ../external_asset/showcase_WIDGET_NAME.gif screenshots/WIDGET_NAME_demo.gif
    
    # Step 5: Generate Example Platforms
    cd flutterfx_WIDGET_NAME/example
    flutter create .
    
    # Step 6: Test
    flutter run
    
    # Step 7: Publish
    cd ..
    dart pub publish --dry-run
    dart pub publish
  8. Customize the iOS launch screen assets

    main

    To change the image displayed during the app's launch on iOS, you can either replace the image files directly in the ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode for a more visual approach.

    Method 1: Direct File Replacement

    Replace the existing image files within the LaunchImage.imageset directory with your own assets.

  9. Update files for a new widget package

    main

    When creating a new widget package from the blur_fade template, you must update the following files to replace blur_fade or WIDGET_NAME with your specific widget's identity:

    FileRequired Changes
    pubspec.yamlReplace blur_fade with WIDGET_NAME and update the description.
    README.mdUpdate the Title, description, GIF link, and usage examples.
    lib/flutterfx_WIDGET_NAME.dartUpdate the library name and the exported files.
    lib/src/Add your widget implementation code (ensure no fx_ imports are used).
    example/pubspec.yamlReplace blur_fade with WIDGET_NAME.
    example/lib/main.dartUpdate the demo code to use your new widget.
  10. Customise FxBottomSheet style with presets and copyWith

    main

    You can style the bottom sheet using built-in presets or by fine-tuning an existing style using copyWith().

    Presets:

    • FxBottomSheetStyle.light(): The default light theme.
    • FxBottomSheetStyle.dark(): A dark theme preset.

    Fine-tuning: Use .copyWith() to override specific visual properties like topBorderRadius, mainContentScale, or mainContentSlide.

    // Using presets
    FxBottomSheet(style: FxBottomSheetStyle.light(), ...)
    FxBottomSheet(style: FxBottomSheetStyle.dark(), ...)
    
    // Fine-tuning with copyWith
    FxBottomSheet(
      style: FxBottomSheetStyle.dark().copyWith(
        topBorderRadius: 28,
        mainContentScale: 0.90,   // less dramatic scale
        mainContentSlide: 16,     // less upward slide
      ),
      maxHeight: 0.75,            // sheet takes 75% of screen height
      ...
    )