Stacked-Org / stacked

A Flutter application architecture created from real world scenarios
MIT License
973 stars 255 forks source link

app.dialogs.dart resets after running stacked generate #1125

Closed pieterbergmans closed 1 month ago

pieterbergmans commented 1 month ago

Describe the bug

Hi,

I’m trying to add a custom dialog called languages. But after I run stacked generate, the code disappears. Is that the intent or am I doing something wrong. The same thing happens with bottomSheets.

My new dialog service…

enum DialogType { infoAlert, languages }

void setupDialogUi() {
  final dialogService = locator<DialogService>();

  final Map<DialogType, DialogBuilder> builders = {
    DialogType.infoAlert: (context, request, completer) =>
        InfoAlertDialog(request: request, completer: completer),
    DialogType.languages: (context, request, completer) => LanguagesDialog(
          request: request,
          completer: completer,
        )
  };

  dialogService.registerCustomDialogBuilders(builders);
}

After running stacked generate

enum DialogType {
  infoAlert,
}

void setupDialogUi() {
  final dialogService = locator<DialogService>();

  final Map<DialogType, DialogBuilder> builders = {
    DialogType.infoAlert: (context, request, completer) =>
        InfoAlertDialog(request: request, completer: completer),
  };

  dialogService.registerCustomDialogBuilders(builders);
}

What operating system do you use?

macOS

Information about the installed tooling

// pubspec.yaml
stacked: ^3.4.0
stacked_services: ^1.1.0
stacked_themes:

// flutter doctor
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.4 23E214 darwin-arm64 (Rosetta), locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Xcode - develop for iOS and macOS (Xcode 15.4)
    ✗ Unable to get list of installed Simulator runtimes.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.91.1)
[✓] Connected device (3 available)
[✓] Network resources

Steps to reproduce the issue

  1. Add custom dialog
  2. run stacked generate

Expected behavior

I would have expected that the app.diaglogs.dart file to maintain the new custom dialog information.

Screenshots

No response

Additional Context

No response

pieterbergmans commented 1 month ago

Sorry, I just read the message // GENERATED CODE - DO NOT MODIFY BY HAND at the top of the app.dialogs.dart page. However, I’d still like help explaining how to create a custom dialog.

pieterbergmans commented 1 month ago

Just figured it out. I needed to add the following to app.dart:

dialogs: [
    StackedDialog(classType: InfoAlertDialog),
    StackedDialog(classType: LanguagesDialog)
    // @stacked-dialog
  ],
sebastianbuechler commented 1 month ago

@pieterbergmans So this can be closed, right?

pieterbergmans commented 1 month ago

@sebastianbuechler - yes, it can.