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

Throw a helpful error when returning an empty list in pageListBuilder #33

Closed
TahaTesser opened this issue Aug 7, 2023 · 1 comment · Fixed by #68
Closed

Throw a helpful error when returning an empty list in pageListBuilder #33

TahaTesser opened this issue Aug 7, 2023 · 1 comment · Fixed by #68
Assignees
Labels
enhancement New feature or request

Comments

@TahaTesser
Copy link
Collaborator

Description

When you return a list empty in the pageListBuilder (this could happen if the provided list is empty or not initialized), it throws an unhelpful error.

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following RangeError was thrown building ValueListenableBuilder<int>(dirty, state:
flutter: _ValueListenableBuilderState<int>#93302):
flutter: RangeError (index): Invalid value: Valid value range is empty: 0

Instead, throw an error that says pageListBuilder is empty and at least one page should be provided.

Code sample

expand to view the code sample
import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          body: Center(
            child: Builder(
              builder: (context) {
                return ElevatedButton(
                  onPressed: () {
                    WoltModalSheet.show(
                      context: context,
                      pageListBuilder: (context) {
                        return <WoltModalSheetPage>[

                        ];
                      },
                    );
                  },
                  child: const Text('Open sheet'),
                );
              }
            ),
          )
        ),
      );
  }
}

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

This issue is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant