ShowCaseView Documentation

repository·master·Indexed 23 days ago

https://github.com/simformsolutionspvtltd/showcaseview

A Flutter package for creating interactive, step-by-step UI tutorials by highlighting specific widgets. It features customizable tooltips, auto-scrolling, animations, and support for multiple widgets simultaneously. The library provides a central manager class, ShowcaseView, to handle interactions and configurations, including support for multiple configuration scopes and programmatic flow control via a singleton.

Tokens
9.5K
Snippets
19
Records
43
Agent score
82%

What's inside ShowCaseView

  1. Overview of ShowCaseView features

    master

    ShowCaseView is a Flutter package designed to create interactive tutorials by highlighting specific widgets step-by-step.

    Key capabilities include:

    • Step-by-step guidance: Highlight specific widgets to guide users through the UI.
    • Customizable tooltips: Configure titles, descriptions, actions, and styling for tooltips.
    • Auto-scrolling: Automatically handles scrolling the target widget into view.
    • Custom Tooltips: Support for providing your own custom tooltip widgets.
    • Animations: Built-in animation and transition effects for tooltips.
    • Multi-widget showcase: Options to showcase multiple widgets simultaneously.
  2. Manage multiple Showcase scopes

    master

    ShowcaseView supports multiple configuration scopes. This allows you to have different settings (e.g., for a 'profile' module vs the rest of the app).

    Registering a Scope

    Use the scope parameter in ShowcaseView.register() to define a unique configuration set.

    Accessing a Scope

    Use ShowcaseView.get(scope: 'your_scope_name') to control showcases within that specific scope.

    Assigning a Showcase to a Scope

    By default, Showcase widgets use the currently active scope. You can explicitly bind a Showcase widget to a specific scope using the scope parameter. This ensures the widget belongs to the correct scope even if multiple scopes are active in the same tree.

    Warning: If multiple scopes are registered with the same name, the last one registered will override previous ones.

    // Register a specific scope
    ShowcaseView.register(
      scope: 'profile',
      // other configurations
    )
    
    // Control showcases in that scope
    ShowcaseView.get(scope: 'profile').startShowCase([_one, _two, _three]);
    
    // Explicitly assign a widget to a scope
    Showcase(
      key: _profileKey,
      scope: 'profile',
      title: 'Profile',
      description: 'Your profile information',
      child: Icon(Icons.person),
    ),
  3. How ShowCaseView works: Key Components

    master

    ShowCaseView uses three primary components to create interactive tutorials:

    • ShowcaseView: The central manager class that handles showcase interactions, configurations, and the lifecycle (registration/unregistration).
    • Showcase: A widget used to wrap a target widget to create a showcase using the default tooltip style.
    • Showcase.withWidget: A widget used to wrap a target widget when you want to provide a completely custom tooltip widget instead of the default one.
  4. Implement a Basic Showcase sequence

    master

    To implement a basic showcase, follow these steps:

    1. Register: Call ShowcaseView.register().
    2. Define Keys: Create GlobalKey instances for each widget you want to highlight.
    3. Wrap Widgets: Wrap your target widgets with the Showcase widget using the defined keys.
    4. Start: Trigger the sequence using ShowcaseView.get().startShowCase([key1, key2, ...]).
    5. Unregister: Call ShowcaseView.get().unregister() when the showcase is no longer needed (e.g., in dispose()).

    Starting the Showcase

    • On Button Press: Call startShowCase inside an onPressed callback.
    • On Screen Load: Use WidgetsBinding.instance.addPostFrameCallback in initState to ensure the UI is rendered before starting.
    • After Animation: Use startShowCase with the delay parameter inside a post-frame callback.
    // 1. Register
    ShowcaseView.register();
    
    // 2. Define Keys
    final GlobalKey _one = GlobalKey();
    final GlobalKey _two = GlobalKey();
    
    // 3. Wrap Widgets
    Showcase(
      key: _one,
      title: 'Menu',
      description: 'Click here to see menu options',
      child: Icon(Icons.menu),
    ),
    
    // 4. Start
    void startShowcase() {
      ShowcaseView.get().startShowCase([_one, _two]);
    }
    
    // 5. Unregister
    @override
    void dispose() {
      ShowcaseView.get().unregister();
      super.dispose();
    }
  5. Install ShowCaseView in Flutter

    master

    To use ShowCaseView in your Flutter project, add the dependency to your pubspec.yaml file and run the install command.

    1. Add to pubspec.yaml:
    dependencies:
      showcaseview: <latest-version>
    1. Run the installation command:
    flutter pub get
    1. Import the package in your Dart files:
    import 'package:showcaseview/showcaseview.dart';
  6. Migrate to ShowCaseView v5.x.x

    master

    Version 5.x.x introduces a major change: it removes the dependency on BuildContext for controlling showcases and moves to an explicit registration lifecycle.

    Key Changes:

    1. No more ShowCaseWidget wrapper: You no longer need to wrap your page with ShowCaseWidget to provide context.
    2. Use ShowcaseView.get(): Control showcases via the singleton instead of ShowCaseWidget.of(context).
    3. Explicit Registration: Use ShowcaseView.register() to set up configurations.
    4. Cleanup: Always call ShowcaseView.get().unregister() in your dispose() method to clean up.
    // After (5.0.0+)
    @override
    void initState() {
      super.initState();
      // Register once
      ShowcaseView.register(
        autoPlayDelay: const Duration(seconds: 3),
        onStart: (index, key) => debugPrint('Started $index'),
      );
    
      WidgetsBinding.instance.addPostFrameCallback((_) {
        // Control via ShowcaseView.get()
        ShowcaseView.get().startShowCase([_one, _two]);
      });
    }
    
    @override
    void dispose() {
      // Always unregister to clean up
      ShowcaseView.get().unregister();
      super.dispose();
    }
  7. Customize the iOS launch screen assets

    master

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

    Using Xcode:

    1. Open your Flutter project's iOS workspace using the command: open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing launch images.
    open ios/Runner.xcworkspace
  8. Migrate from previous versions

    master

    Migrating from v4.x.x to v4.0.0+

    Parameter names for text alignment have changed to better reflect their purpose:

    • titleAlignment $\rightarrow$ titleTextAlign
    • descriptionAlignment $\rightarrow$ descriptionTextAlign

    Migrating from v3.x.x to v3.0.0+

    The ShowCaseWidget no longer requires a Builder widget; it now accepts a builder function directly.

  9. Configure tooltip action button placement

    master

    Tooltip action buttons can be applied in two scopes:

    1. Local Actions: Specific to a single showcase tooltip. Provide them via the tooltipActions property in a Showcase widget.
    2. Global Actions: Appear in all showcase tooltips. Provide them via the globalTooltipActions property in the ShowcaseView widget.

    The visual position (inside or outside the tooltip container) and alignment are managed by the TooltipActionConfig class.