Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to add a custom loading indicator #102

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

stan-at-work
Copy link

@stan-at-work stan-at-work commented Dec 3, 2024

Fix: #92

How to Use setCustomLoadingIndicator in PlutoGrid

The setCustomLoadingIndicator method allows you to define a custom widget to display as the loading indicator in a PlutoGrid. Below is an explanation based on the provided example.


Step-by-Step Usage

1. Define a Custom Loading Indicator

Create a custom widget that represents your loading indicator. This widget will be shown when the grid is in a loading state.

In the provided code, the CustomIndicator widget does the following:

  • Creates a semi-transparent white overlay.
  • Displays a "Custom Loading Indicator" text in the center.
class CustomIndicator extends StatelessWidget {
  const CustomIndicator({super.key});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned.fill(
          child: ColoredBox(
            color: Colors.white.withOpacity(0.5),
          ),
        ),
        Center(
          child: Text('Custom Loading Indicator'),
        ),
      ],
    );
  }
}

2. Set the Custom Loading Indicator

In the onLoaded callback of the PlutoGrid, use the setCustomLoadingIndicator method to set your custom widget:

onLoaded: (event) {
  stateManager = event.stateManager;
  // Set custom loading indicator
  stateManager?.setCustomLoadingIndicator(
    (context) => const CustomIndicator(),
  );
},

3. Toggle the Loading Indicator

You can programmatically control the visibility of the loading indicator using stateManager?.setShowLoading.

In the provided code:

  • A FloatingActionButton toggles the visibility of the loading indicator.
  • The PlutoGridLoadingLevel.custom is used to specify the loading level.
floatingActionButton: FloatingActionButton(
  onPressed: () {
    // Toggle loading visibility
    stateManager?.setShowLoading(
      stateManager?.showLoading == false,
      level: PlutoGridLoadingLevel.custom, // Specify loading level
    );
  },
  child: const Icon(Icons.refresh),
),

Full Flow

  1. Start the App: When you run the app, the PlutoGrid displays the rows and columns.
  2. Press the FloatingActionButton: This toggles the loading indicator's visibility.
  3. Custom Indicator: Instead of the default loader, your custom widget (CustomIndicator) appears.

Key Points

  • Customization: Your loading indicator can include any widget (e.g., progress bars, animations, or custom graphics).
  • Dynamic Control: Use setShowLoading and setLoadingLevel to toggle and scope the loading states.

image

@doonfrs
Copy link
Owner

doonfrs commented Dec 3, 2024

Thank you, that was required!
because the change is big, I await another approval/review before merging.

@stan-at-work
Copy link
Author

Thank you, that was required! because the change is big, I await another approval/review before merging.

approval/review from who ?

@doonfrs
Copy link
Owner

doonfrs commented Dec 10, 2024

Thank you for the feature, it is really required.
you need to resolve the conflict, please bro let's try to make sure the diff only related to the changes, otherwise, it is not easy to review a big change.

@stan-at-work
Copy link
Author

Thank you for the feature, it is really required.

you need to resolve the conflict, please bro let's try to make sure the diff only related to the changes, otherwise, it is not easy to review a big change.

To fix the file changes i created: #108
Its a formatting issue.

# Conflicts:
#	demo/lib/main.dart
#	demo/lib/screen/home_screen.dart
#	demo/pubspec.yaml
#	lib/src/pluto_grid.dart
#	lib/src/ui/columns/pluto_column_filter.dart
@stan-at-work
Copy link
Author

stan-at-work commented Dec 17, 2024

@doonfrs I can't fix this anymore.

You can change this toggle so you dont see any white space changes.

image

This can help for you


This happens if someone saves a file on a machine that has it's end of line seperator set to eather LF or CRLF

If someone saves a file with CRLF and i save the file again with possibly LF all those line endings are changes, and git thinks all the files are changed.

with the whitespace settings you can disable the checking of those end of line seperator's and see the actual code that changed.

image
image

In vscode a fixed one can be changed.

image

I will set the fixed end of line seperator to LF in this PR => #122

Coud you re look at this PR. and possible merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Ability to Customize Default Loading Widget
2 participants