zefyr icon indicating copy to clipboard operation
zefyr copied to clipboard

Is it possible to add a custom item to zefyr toolbar.

Open Hanggi opened this issue 7 years ago • 9 comments

The zefyr is great work(Although I don't know how to read it).

Is there a method can add a new custom item to the toolbar, and delete some tools which I will not use.

For example, I want to add a Name Card Widget with the toolbar, and display a custom widget. Thank you.

Hanggi avatar Dec 14 '18 11:12 Hanggi

There is currently no API that allows registering custom embed types and extending toolbar. This is something I'd like to add though.

Make sure to 👍 this issue. This would make it higher in priority list.

pulyaevskiy avatar Dec 14 '18 18:12 pulyaevskiy

There's no deleting widget option either?

I assume deleting and adding would require same logic (to modify the toolbar actions list).

orafal-dev avatar Feb 14 '19 17:02 orafal-dev

You are correct.

I've actually started some work on refactoring of the toolbar, so this issue can be considered "in progress". I have no ETA at this point yet though.

pulyaevskiy avatar Feb 14 '19 17:02 pulyaevskiy

@pulyaevskiy What's the progress on this? Is it still not possible to add custom items? Really appreciate the hard work you're putting into this project.

garrrettt avatar Jul 31 '19 18:07 garrrettt

@pulyaevskiy Were you able to finish this, I would like to join if you need my help

Adokiye avatar Jan 21 '20 15:01 Adokiye

Not a lot of progress here yet. Just got back to work on Zefyr after a while.

Just want to remind everyone Zefyr is a dev preview at the moment. This means that underlying implementation is far from perfect. This is one obstacle preventing from easily extending it.

Still this is on my roadmap and I’d like this to be part of 1.0 release.

Right now I’m working on cleaning up rendering layer which should address a few bugs and feature requests. And it should also enable this feature request. Though all I can say at this point is it’s coming, likely in the first half of the year.

pulyaevskiy avatar Jan 21 '20 15:01 pulyaevskiy

@pulyaevskiy Is there anything new about this function ? :)

Dorbmon avatar Mar 31 '20 11:03 Dorbmon

is steel nothing?

modeckrus avatar Jun 22 '20 23:06 modeckrus

My congratulations. I did it. I just create a custom zefyrToolbarDelegate and passed it to ZefyrEditor

code for custom delegate:

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

class MDZefyrToolbarDelegate implements ZefyrToolbarDelegate {
  static const kDefaultButtonIcons = {
    ZefyrToolbarAction.bold: Icons.format_bold,
    ZefyrToolbarAction.italic: Icons.format_italic,
    ZefyrToolbarAction.link: Icons.link,
    ZefyrToolbarAction.unlink: Icons.link_off,
    ZefyrToolbarAction.clipboardCopy: Icons.content_copy,
    ZefyrToolbarAction.openInBrowser: Icons.open_in_new,
    ZefyrToolbarAction.heading: Icons.format_size,
    ZefyrToolbarAction.bulletList: Icons.format_list_bulleted,
    ZefyrToolbarAction.numberList: Icons.format_list_numbered,
    ZefyrToolbarAction.code: Icons.code,
    ZefyrToolbarAction.quote: Icons.format_quote,
    ZefyrToolbarAction.horizontalRule: Icons.remove,
    ZefyrToolbarAction.image: Icons.photo,
    ZefyrToolbarAction.cameraImage: Icons.photo_camera,
    ZefyrToolbarAction.galleryImage: Icons.photo_library,
    ZefyrToolbarAction.hideKeyboard: Icons.keyboard_hide,
    ZefyrToolbarAction.close: Icons.close,
    ZefyrToolbarAction.confirm: Icons.check,
    ZefyrToolbarAction.values: []
  };

  static const kSpecialIconSizes = {
    ZefyrToolbarAction.unlink: 20.0,
    ZefyrToolbarAction.clipboardCopy: 20.0,
    ZefyrToolbarAction.openInBrowser: 20.0,
    ZefyrToolbarAction.close: 20.0,
    ZefyrToolbarAction.confirm: 20.0,
  };

  static const kDefaultButtonTexts = {
    ZefyrToolbarAction.headingLevel1: 'H1',
    ZefyrToolbarAction.headingLevel2: 'H2',
    ZefyrToolbarAction.headingLevel3: 'H3',
  };

  static const kExtend = {ZefyrToolbarAction.image: 'gey'};

  @override
  Widget buildButton(BuildContext context, ZefyrToolbarAction action,
      {VoidCallback onPressed}) {
    final theme = Theme.of(context);
    if (kExtend.containsKey(action)) {
      final icon = kDefaultButtonIcons[action];
      final size = kSpecialIconSizes[action];
      final theme = Theme.of(context);
      final width = theme.buttonTheme.constraints.minHeight + 4.0;
      final constraints = theme.buttonTheme.constraints.copyWith(
          minWidth: width, maxHeight: theme.buttonTheme.constraints.minHeight);
      final radius = BorderRadius.all(Radius.circular(3.0));

      return Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ZefyrButton.icon(
            action: action,
            icon: icon,
            iconSize: size,
            onPressed: onPressed,
          ),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 1.0, vertical: 6.0),
            child: RawMaterialButton(
              shape: RoundedRectangleBorder(borderRadius: radius),
              elevation: 0.0,
              constraints: constraints,
              onPressed: (){
                print('work perfictly');
              },
              child: Icon(Icons.add),
            ),
          ),
        ],
      );
    } else if (kDefaultButtonIcons.containsKey(action)) {
      final icon = kDefaultButtonIcons[action];
      final size = kSpecialIconSizes[action];
      return ZefyrButton.icon(
        action: action,
        icon: icon,
        iconSize: size,
        onPressed: onPressed,
      );
    } else {
      final text = kDefaultButtonTexts[action];
      assert(text != null);
      final style = theme.textTheme.caption
          .copyWith(fontWeight: FontWeight.bold, fontSize: 14.0);
      return ZefyrButton.text(
        action: action,
        text: text,
        style: style,
        onPressed: onPressed,
      );
    }
  }
}


modeckrus avatar Jun 22 '20 23:06 modeckrus