introduction_screen

repository·master·Indexed 20 days ago

https://github.com/pyozer/introduction_screen

A highly customizable Flutter widget for creating onboarding or introductory screens. It supports structured layouts via PageViewModel or completely custom layouts via rawPages, featuring configurable navigation controls (Next, Skip, Back, Done), customizable progress dots via DotsDecorator, and programmatic control using a GlobalKey<IntroductionScreenState>.

Tokens
8.3K
Snippets
17
Records
24
Agent score
65%

What's inside introduction_screen

  1. How PageViewModel works

    master

    A PageViewModel represents a single page within the introduction sequence. You provide a list of these objects to the pages parameter of the IntroductionScreen widget.

    Key capabilities:

    • Content: Define text using title and body (Strings), or use titleWidget and bodyWidget to provide custom Widgets. Note: You must use either body or bodyWidget, not both.
    • Visuals: Use the image parameter to display any Widget (e.g., Icon, Image.asset, Image.network).
    • Styling: Use the decoration parameter (of type PageDecoration) to customize pageColor, titleTextStyle, and bodyTextStyle for that specific page.
    PageViewModel(
      title: "Title of page",
      body: "Description text",
      image: const Center(child: Icon(Icons.star)),
      decoration: const PageDecoration(
        pageColor: Colors.blue,
        titleTextStyle: TextStyle(color: Colors.white),
      ),
    )
  2. Customize iOS launch screen assets

    master

    To customize the iOS launch screen for your Flutter project, you can use one of two methods:

    1. Direct File Replacement: Replace the existing image files directly within the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.
    2. Xcode Interface:
      • Open the iOS workspace using 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
  3. Control IntroductionScreen programmatically using a GlobalKey

    master

    To trigger navigation (next, previous, skip, etc.) in response to custom user input or external events, use a GlobalKey<IntroductionScreenState>.

    1. Define a GlobalKey<IntroductionScreenState> in your parent widget's state.
    2. Pass this key to the key parameter of the IntroductionScreen.
    3. Access the currentState of the key to call methods like:
      • next()
      • previous()
      • skipToEnd()
      • animateScroll()
    final _introKey = GlobalKey<IntroductionScreenState>();
    
    // Inside build method
    IntroductionScreen(
      key: _introKey,
      pages: [...],
      // ...
    )
    
    // To trigger next page
    _introKey.currentState?.next();
  4. Configure IntroductionScreen layout and appearance

    master

    Use these IntroductionScreen parameters to control the global layout and styling:

    Global Layout

    • globalBackgroundColor: Background color for all pages. Use Colors.transparent to allow background images to show through.
    • globalHeader: A widget displayed at the top of all pages.
    • globalFooter: A widget displayed at the bottom of all pages.
    • pagesAxis: The axis of scrolling (Axis.horizontal or Axis.vertical).
    • showBottomPart: If true, shows the area containing skip/next/done buttons.
    • controlsPosition: The Position of the controls (Default: const Position(left: 0, right: 0, bottom: 0)).
    • controlsMargin, controlsPadding: Spacing for the controls container.

    Progress Dots

    • isProgress: Show/hide the progress dots (Default: true).
    • isProgressTap: Enable/disable tapping on dots to navigate (Default: true).
    • dotsDecorator: Customizes the dots (size, shape, color, spacing).
    • dotsContainerDecorator: Customizes the container holding the dots and buttons.
    • customProgress: Provide a custom widget to replace the dots indicator.

    Animation and Physics

    • animationDuration: Duration of the page transition (Default: 350).
    • curve: The animation curve (Default: Curves.easeIn).
    • scrollPhysics: The ScrollPhysics for the PageView (Default: BouncingScrollPhysics()).
    • freeze: If true, freezes the scroll (Default: false).
  5. Configure IntroductionScreen pages

    master

    You can define the content of your introduction screen using two different approaches:

    1. Using PageViewModel: Provide a list of PageViewModel objects to the pages parameter. This is the standard way to use the library's predefined layout.
    2. Using Custom Widgets: Provide a list of arbitrary widgets to the rawPages parameter.

    Note: If you provide both rawPages and pages, the pages parameter will take precedence.

    IntroductionScreen(
      pages: [ 
        PageViewModel(
          title: "Welcome",
          body: "This is the first page",
          image: AssetImage("assets/intro.png"),
        ),
      ],
    )
  6. Customize navigation buttons

    master

    You can customize the appearance and behavior of the navigation buttons (Skip, Next, Done, Back) using two methods:

    1. Simple Customization: Pass a widget to skip, next, done, or back to replace the default TextButton content.
    2. Full Override: Use overrideSkip, overrideNext, overrideDone, or overrideBack to provide a custom builder function. This gives you full control over the button's structure and provides the onPressed callback.

    Important: If you enable a button via showSkipButton, showNextButton, showDoneButton, or showBackButton, you must provide either the simple widget or the override builder, otherwise the widget will throw an assertion error.

  7. Configure the IntroductionScreen widget

    master

    The IntroductionScreen widget manages the navigation and display of your list of PageViewModels.

    Navigation Controls:

    • Next Button: Controlled by showNextButton. If you don't provide a next widget, you must set showNextButton: false.
    • Skip Button: To show a skip button on all pages except the last, set showSkipButton: true and provide a skip widget.
    • Back Button: To show a back button on all pages except the first, set showBackButton: true and provide a back widget.
    • Done Button: If showDoneButton is true, you must provide a done widget and an onDone callback.

    Styling Buttons:

    • Use baseBtnStyle to apply a common TextButton.styleFrom to all buttons (Back, Skip, Next, Done).
    • Use specific style parameters (backStyle, skipStyle, nextStyle, doneStyle) to override the base style for individual buttons. Specific styles are merged with the baseBtnStyle.
    IntroductionScreen(
      pages: listPagesViewModel,
      showSkipButton: true,
      skip: const Text("Skip"),
      next: const Text("Next"),
      done: const Text("Done"),
      onDone: () {
        // Handle completion
      },
      baseBtnStyle: TextButton.styleFrom(backgroundColor: Colors.grey.shade200),
      skipStyle: TextButton.styleFrom(foregroundColor: Colors.red),
    )
  8. Customize PageDecoration

    master

    Use PageDecoration to control the visual appearance of individual pages.

    Note: You cannot use both pageColor and boxDecoration simultaneously.

    Styling

    • pageColor: Background color of the page.
    • boxDecoration: BoxDecoration for the page container.
    • titleTextStyle: TextStyle for the title.
    • bodyTextStyle: TextStyle for the body.

    Layout and Flex

    • imageFlex: Flex ratio of the image.
    • bodyFlex: Flex ratio of the content (title/body).
    • footerFlex: Flex ratio of the footer.
    • imagePadding: Padding around the image widget.
    • contentPadding: Padding around the title/body/footer.
    • titlePadding: Padding specifically for the title.
    • descriptionPadding: Padding specifically for the body.
    • footerPadding: Padding specifically for the footer.
    • bodyAlignment: Alignment of the content (Default: Align.topCenter).
    • imageAlignment: Alignment of the image (Default: Align.bottomCenter).
    • fullScreen: If true, sets the image as a fullscreen background (Default: false).
  9. Customize dots indicators with DotsDecorator

    master

    You can customize the progress dots at the bottom of the screen using the dotsDecorator parameter. This accepts a DotsDecorator object, allowing you to control size, color, spacing, and shape.

    IntroductionScreen(
      pages: listPagesViewModel,
      dotsDecorator: DotsDecorator(
        size: const Size.square(10.0),
        activeSize: const Size(20.0, 10.0),
        activeColor: Colors.blue,
        color: Colors.black26,
        spacing: const EdgeInsets.symmetric(horizontal: 3.0),
        activeShape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.0)
        ),
      ),
      // ... other parameters
    )
  10. Customize IntroductionScreen buttons

    master

    You can customize buttons in two ways: using pre-made widgets or providing entirely custom widgets.

    Pre-made Buttons

    Use these parameters to provide a simple widget (like Text) for the buttons:

    • done: The widget for the Done button. (Requires onDone callback).
    • next: The widget for the Next button.
    • skip: The widget for the Skip button.
    • back: The widget for the Back button.

    Custom Buttons (Overrides)

    If you want full control over the button's implementation, use the override parameters. These have priority over the pre-made button parameters:

    • overrideDone: Custom Done button widget.
    • overrideNext: Custom Next button widget.
    • overrideSkip: Custom Skip button widget.
    • overrideBack: Custom Back button widget.

    Button Visibility

    Control whether buttons are shown using:

    • showDoneButton: (Default: true)
    • showNextButton: (Default: true)
    • showSkipButton: (Default: false)
    • showBackButton: (Default: false)

    Button Styling

    • baseBtnStyle: Apply a global style to all buttons.
    • skipStyle, nextStyle, doneStyle, backStyle: Apply specific styles to individual buttons.
  11. Handle IntroductionScreen callbacks

    master

    Use the following callbacks to respond to user interactions:

    • onDone: () {}: Triggered when the 'Done' button is pressed. Required if you define a done widget (unless showDoneButton is false).
    • onSkip: () {}: Triggered when the 'Skip' button is pressed. By default, skipping goes to the last page.
    • onChange: (page) {}: Triggered whenever the page changes. Receives the current page index.
    IntroductionScreen(
      onDone: () => print("Done!"),
      onSkip: () => print("Skipped"),
      onChange: (index) => print("Current page: $index"),
      pages: [...],
    )