Skip to content

Custom toolbar bug #2511

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

Open
1 task done
ifuterman opened this issue Mar 12, 2025 · 4 comments
Open
1 task done

Custom toolbar bug #2511

ifuterman opened this issue Mar 12, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ifuterman
Copy link

ifuterman commented Mar 12, 2025

Have you checked for an existing issue?

Flutter Quill Version

11.1.0

Steps to Reproduce

Create a custom toolbar like this :

Column(
        children: [
          Row(
            children: [
              QuillToolbarToggleStyleButton(
                controller: controller,
                attribute: Attribute.list,
                baseOptions: QuillToolbarBaseButtonOptions(),
                options: QuillToolbarToggleStyleButtonOptions(
                  childBuilder: (_, __){
                    return Container(
                      height: 50,
                      width: 50,
                      color: Colors.red,
                    );
                  }
                ),
              )
            ],
          ),
          Expanded(
            child: QuillEditor(
              focusNode: focusNode,
              scrollController: ScrollController(),
              controller: controller
            )
          )
        ],
      )

Expected results

A button in form of red quadrate.

Actual results

Exception:
The following _TypeError was thrown building QuillToolbarToggleStyleButton(dirty, state: QuillToolbarToggleStyleButtonState#1b19f):
TypeError: Instance of '(QuillToolbarToggleStyleButtonOptions, QuillToolbarToggleStyleButtonExtraOptions) => Container': type '(QuillToolbarToggleStyleButtonOptions, QuillToolbarToggleStyleButtonExtraOptions) => Container' is not a subtype of type '((dynamic, dynamic) => Widget)?'

Additional Context

Screenshots / Video demonstration

[Attach media here]

In previous versions it was possible to add custom childBuilder in button options, now it is not possible. It works if use the baseOptions property with the same custom childBuilder but it is not documented
Logs
[Paste logs here]
@ifuterman ifuterman added the bug Something isn't working label Mar 12, 2025
@CatHood0
Copy link
Collaborator

CatHood0 commented Mar 14, 2025

Could you send me the full stack trace? It would be very helpful to know exactly where the error is.

To answer your question, no, we didn't change the implementation of childBuilder at any point. It should always accept any widget you return. In itself, it's strange that it's already throwing this error.

@CatHood0 CatHood0 self-assigned this Mar 14, 2025
@CatHood0 CatHood0 added the awaiting response Pending additional information or feedback from the issue creator label Mar 14, 2025
@ifuterman
Copy link
Author

ifuterman commented Mar 16, 2025

======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building QuillToolbarToggleStyleButton(dirty, state: QuillToolbarToggleStyleButtonState#db6d6):
TypeError: Instance of '(QuillToolbarToggleStyleButtonOptions, QuillToolbarToggleStyleButtonExtraOptions) 
 => Container': type 
   '(QuillToolbarToggleStyleButtonOptions, QuillToolbarToggleStyleButtonExtraOptions) 
      => Container' is not a subtype of type '((dynamic, dynamic) => Widget)?'

The relevant error-causing widget was: 
  QuillToolbarToggleStyleButton =>
      QuillToolbarToggleStyleButton:file:///Users/iosiffuterman/IdeaProjects/quill_test/lib/main.dart:78:15
When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3            throw_
dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 110:39                      _failedAsCheck
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1395:3                                   _generalNullableAsCheckImplementation
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1278:30                                  _installSpecializedAsCheck
packages/flutter_quill/src/toolbar/base_button/base_button_options_resolver.dart 36:7  get childBuilder
packages/flutter_quill/src/toolbar/base_button/base_value_button.dart 56:24            get childBuilder
packages/flutter_quill/src/toolbar/buttons/toggle_style_button.dart 109:31             build
packages/flutter/src/widgets/framework.dart 5743:27                                    build
packages/flutter/src/widgets/framework.dart 5631:15                                    performRebuild
packages/flutter/src/widgets/framework.dart 5794:11                                    performRebuild
packages/flutter/src/widgets/framework.dart 5347:7                                     rebuild
packages/flutter/src/widgets/framework.dart 5613:5                                     [_firstBuild]
packages/flutter/src/widgets/framework.dart 5785:11                                    [_firstBuild]
packages/flutter/src/widgets/framework.dart 5607:5                                     mount

@ifuterman
Copy link
Author

ifuterman commented Mar 16, 2025

import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      localizationsDelegates: FlutterQuillLocalizations.localizationsDelegates,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final controller = QuillController(
    document: Document(),
    selection: TextSelection.collapsed(offset: 0)
  );
  final focusNode = FocusNode();
  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      body: Column(
        children: [
          Row(
            children: [
              QuillToolbarToggleStyleButton(
                controller: controller,
                attribute: Attribute.list,
                baseOptions: QuillToolbarBaseButtonOptions(),
                options: QuillToolbarToggleStyleButtonOptions(
                  childBuilder: (_, __){
                    return Container(
                      height: 50,
                      width: 50,
                      color: Colors.yellow,
                    );
                  }
                ),
              )
            ],
          ),
          Expanded(
            child: QuillEditor(
              focusNode: focusNode,
              scrollController: ScrollController(),
              controller: controller
            )
          )
        ],
      )
    );
  }
}

@CatHood0 CatHood0 removed the awaiting response Pending additional information or feedback from the issue creator label Mar 19, 2025
@CatHood0
Copy link
Collaborator

Thanks so much for the full bug report. As soon as I finish the PRs I currently have open, I'll focus on figuring out why this is suddenly failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants