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

Allow custom color of image editor icon #38

Closed
thanglq1 opened this issue May 7, 2024 · 13 comments
Closed

Allow custom color of image editor icon #38

thanglq1 opened this issue May 7, 2024 · 13 comments
Labels
enhancement New feature or request

Comments

@thanglq1
Copy link

thanglq1 commented May 7, 2024

Platforms

Android, iOS

Description

Currently, ImageEditorIcons only support custom image editor icons. It would be even better if we could customize the color of the image editor icons as well

@thanglq1 thanglq1 added the enhancement New feature or request label May 7, 2024
@hm21
Copy link
Owner

hm21 commented May 7, 2024

Thanks for your future request. May I ask, do you need to change the color of every icon differently, or you just want to change a set of color? For example, if you want to change the icon color of all icons inside the appBar or bottomBar, you can change the color inside ImageEditorTheme.

As example:

imageEditorTheme: const ImageEditorTheme(
      appBarBackgroundColor: Color(0xFF000000),
      appBarForegroundColor: Color(0xFFFFFFFF),
       paintingEditor: PaintingEditorTheme(
        appBarBackgroundColor: Color.fromARGB(255, 20, 99, 189),
        appBarForegroundColor: Color(0xFFE1E1E1),
        bottomBarColor: Color.fromARGB(255, 136, 0, 84),
        bottomBarActiveItemColor: Color.fromARGB(255, 46, 0, 58),
        bottomBarInactiveItemColor: Color.fromARGB(255, 223, 255, 210),
      ),
      textEditor: TextEditorTheme(
        appBarBackgroundColor: Color.fromARGB(255, 0, 17, 255),
        appBarForegroundColor: Color(0xFFE1E1E1),
      ),
)

@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Thanks for your future request. May I ask, do you need to change the color of every icon differently, or you just want to change a set of color? For example, if you want to change the icon color of all icons inside the appBar or bottomBar, you can change the color inside ImageEditorTheme.

As example:

imageEditorTheme: const ImageEditorTheme(
      appBarBackgroundColor: Color(0xFF000000),
      appBarForegroundColor: Color(0xFFFFFFFF),
       paintingEditor: PaintingEditorTheme(
        appBarBackgroundColor: Color.fromARGB(255, 20, 99, 189),
        appBarForegroundColor: Color(0xFFE1E1E1),
        bottomBarColor: Color.fromARGB(255, 136, 0, 84),
        bottomBarActiveItemColor: Color.fromARGB(255, 46, 0, 58),
        bottomBarInactiveItemColor: Color.fromARGB(255, 223, 255, 210),
      ),
      textEditor: TextEditorTheme(
        appBarBackgroundColor: Color.fromARGB(255, 0, 17, 255),
        appBarForegroundColor: Color(0xFFE1E1E1),
      ),
)

Hi @hm21. Some icon dont have such as EmojiEditorTheme or StickerEditorTheme so now i'm using custom widget icon.

hm21 added a commit that referenced this issue May 8, 2024
Move all theme based configurations from `EmojiEditorConfigs` to `EmojiEditorTheme` within `ImageEditorTheme`.
This resolves issue #38.
@hm21
Copy link
Owner

hm21 commented May 8, 2024

Hi @thanglq1

Exactly, the StickerEditorTheme doesn't have an option to style anything currently because we build the sticker editor outside the ProImageEditor widget and just push the layer inside, as you can see in this example. This allows you to completely design it by yourself.

The EmojiEditorTheme actually supports it to change the whole theme, but to be honest, I made a mistake and put the theme configurations inside EmojiEditorConfigs and not inside EmojiEditorTheme which is inside ImageEditorTheme. Anyway, I updated it to version 2.7.4 which should allow you to change all colors like in the other editors.

Is this enough, or do you need to have the possibility to change the color of each icon separately? Actually, I can add an option for each icon to set a separate color, but I'm a bit afraid that it will be too many theme configurations which will make it hard for users to understand the theme configurations. For a lot of customization, I currently give the users the option to replace the full appbar and bottombar with their solution, like in this example.

@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Thank you. I will close this issue.

@thanglq1 thanglq1 closed this as completed May 8, 2024
@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Hi @hm21. Sorry, I think I need reopen this issue. In ImageEditorTheme dont have any option to change color of close editor, undo, redo, done button.

@thanglq1 thanglq1 reopened this May 8, 2024
@hm21
Copy link
Owner

hm21 commented May 8, 2024

Do you need to change a different color for each icon, or just the same color for all? If you want to change the same color for all, you can change the appBarForegroundColor like below:

imageEditorTheme: const ImageEditorTheme(
           appBarForegroundColor: Colors.black,
)

@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Do you need to change a different color for each icon, or just the same color for all? If you want to change the same color for all, you can change the appBarForegroundColor like below:

imageEditorTheme: const ImageEditorTheme(
           appBarForegroundColor: Colors.black,
)

How to custom a different color of each icon? And when I use custom widget Icon, dont have option to change color of PaintModeBottomBarItem

@hm21
Copy link
Owner

hm21 commented May 8, 2024

In the paint editor in the bottom bar you can set bottomBarInactiveItemColor and bottomBarActiveItemColor which allow you to set a different color for the selected mode. If you want to customize each icon separately, you can simply replace the appbar with a complete custom solution of your own. This allows you to change any configuration as you like. You can check out this example how to change the appBar or bottomBar.

@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Yes, I saw your example and I tried to change the color of paint editor. I added the below code but it does not work (when we custom widget, custom bottomBar)

imageEditorTheme: const ImageEditorTheme(
            paintingEditor: PaintingEditorTheme(
              bottomBarActiveItemColor: Colors.red,
              bottomBarInactiveItemColor: Colors.yellow,
            ),
          ),

@hm21
Copy link
Owner

hm21 commented May 8, 2024

Did I understand you correctly that in custom widgets you set your own appbar and bottombar for the image editor, right? If yes, then you need to set the color in the custom widget because you are overriding the existing stuff with your widget. If you use the code from the example, you can change it here:

Builder(
          builder: (_) {
            var item = paintModes[index];
            var color = editorKey.currentState?.paintingEditor
                        .currentState?.paintMode ==
                    item.mode
                ? imageEditorPrimaryColor // TODO: set here your selected color
                : const Color(0xFFEEEEEE);

            return FlatIconTextButton(
              label: Text(
                item.label,
                style: TextStyle(fontSize: 10.0, color: color),
              ),
              icon: Icon(item.icon, color: color),
              onPressed: () {
                editorKey
                    .currentState?.paintingEditor.currentState
                    ?.setMode(item.mode);
                setState(() {});
              },
            );
          },
        ),

@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

I'm following your example. I can not change color of paint editor.PaintModeBottomBarItem dont have any option to change color. I also tried this but does not work

imageEditorTheme: const ImageEditorTheme(
            paintingEditor: PaintingEditorTheme(
              bottomBarActiveItemColor: Colors.red,
              bottomBarInactiveItemColor: Colors.yellow,
            ),
          ),

following your example code here

  final List<PaintModeBottomBarItem> paintModes = [
    const PaintModeBottomBarItem(
      mode: PaintModeE.freeStyle,
      icon: Icons.edit,
      label: 'Freestyle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.arrow,
      icon: Icons.arrow_right_alt_outlined,
      label: 'Arrow',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.line,
      icon: Icons.horizontal_rule,
      label: 'Line',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.rect,
      icon: Icons.crop_free,
      label: 'Rectangle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.circle,
      icon: Icons.lens_outlined,
      label: 'Circle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.dashLine,
      icon: Icons.power_input,
      label: 'Dash line',
    ),
  ];

Widget _bottomBarPaintingEditor(BoxConstraints constraints) {
    return StreamBuilder(
      stream: _updateUIStream.stream,
      builder: (_, __) {
        return Scrollbar(
          controller: _bottomBarScrollCtrl,
          scrollbarOrientation: ScrollbarOrientation.top,
          thickness: isDesktop ? null : 0,
          child: BottomAppBar(
            height: kBottomNavigationBarHeight,
            // color: Colors.black,
            color: Colors.green,
            padding: EdgeInsets.zero,
            child: Center(
              child: SingleChildScrollView(
                controller: _bottomBarScrollCtrl,
                scrollDirection: Axis.horizontal,
                child: ConstrainedBox(
                  constraints: BoxConstraints(
                    minWidth: min(constraints.maxWidth, 500),
                    maxWidth: 500,
                  ),
                  child: Wrap(
                    direction: Axis.horizontal,
                    alignment: WrapAlignment.spaceAround,
                    children: <Widget>[
                      FlatIconTextButton(
                        label: Text('My Button',
                            style:
                                _bottomTextStyle.copyWith(color: Colors.amber)),
                        icon: const Icon(
                          Icons.new_releases_outlined,
                          size: 22.0,
                          color: Colors.amber,
                        ),
                        onPressed: () {},
                      ),
                      ...List.generate(
                        paintModes.length,
                        (index) => Builder(
                          builder: (_) {
                            var item = paintModes[index];
                            var color = editorKey.currentState?.paintingEditor
                                        .currentState?.paintMode ==
                                    item.mode
                                ? imageEditorPrimaryColor
                                : const Color(0xFFEEEEEE);

                            return FlatIconTextButton(
                              label: Text(
                                item.label,
                                style: TextStyle(fontSize: 10.0, color: color),
                              ),
                              icon: Icon(item.icon, color: color),
                              onPressed: () {
                                editorKey
                                    .currentState?.paintingEditor.currentState
                                    ?.setMode(item.mode);
                                setState(() {});
                              },
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }

@hm21
Copy link
Owner

hm21 commented May 8, 2024

As I said in my post before, you need to change the color inside the custom widget because you are overriding the existing one. It's useless to do anything in the theme if you create your own widget. Below is the updated version of your code that you use from the example that set the color to red and yellow:

  final List<PaintModeBottomBarItem> paintModes = [
    const PaintModeBottomBarItem(
      mode: PaintModeE.freeStyle,
      icon: Icons.edit,
      label: 'Freestyle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.arrow,
      icon: Icons.arrow_right_alt_outlined,
      label: 'Arrow',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.line,
      icon: Icons.horizontal_rule,
      label: 'Line',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.rect,
      icon: Icons.crop_free,
      label: 'Rectangle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.circle,
      icon: Icons.lens_outlined,
      label: 'Circle',
    ),
    const PaintModeBottomBarItem(
      mode: PaintModeE.dashLine,
      icon: Icons.power_input,
      label: 'Dash line',
    ),
  ];

Widget _bottomBarPaintingEditor(BoxConstraints constraints) {
    return StreamBuilder(
      stream: _updateUIStream.stream,
      builder: (_, __) {
        return Scrollbar(
          controller: _bottomBarScrollCtrl,
          scrollbarOrientation: ScrollbarOrientation.top,
          thickness: isDesktop ? null : 0,
          child: BottomAppBar(
            height: kBottomNavigationBarHeight,
            // color: Colors.black,
            color: Colors.green,
            padding: EdgeInsets.zero,
            child: Center(
              child: SingleChildScrollView(
                controller: _bottomBarScrollCtrl,
                scrollDirection: Axis.horizontal,
                child: ConstrainedBox(
                  constraints: BoxConstraints(
                    minWidth: min(constraints.maxWidth, 500),
                    maxWidth: 500,
                  ),
                  child: Wrap(
                    direction: Axis.horizontal,
                    alignment: WrapAlignment.spaceAround,
                    children: <Widget>[
                      FlatIconTextButton(
                        label: Text('My Button',
                            style:
                                _bottomTextStyle.copyWith(color: Colors.amber)),
                        icon: const Icon(
                          Icons.new_releases_outlined,
                          size: 22.0,
                          color: Colors.amber,
                        ),
                        onPressed: () {},
                      ),
                      ...List.generate(
                        paintModes.length,
                        (index) => Builder(
                          builder: (_) {
                            var item = paintModes[index];
                            /// TODO: set your colors below
                             var color = editorKey.currentState?.paintingEditor
                                        .currentState?.paintMode ==
                                    item.mode
                                ? Colors.red
                                : Colors.yellow;

                            return FlatIconTextButton(
                              label: Text(
                                item.label,
                                style: TextStyle(fontSize: 10.0, color: color),
                              ),
                              icon: Icon(item.icon, color: color),
                              onPressed: () {
                                editorKey
                                    .currentState?.paintingEditor.currentState
                                    ?.setMode(item.mode);
                                setState(() {});
                              },
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }

@hm21 hm21 closed this as completed May 8, 2024
@hm21 hm21 reopened this May 8, 2024
@thanglq1
Copy link
Author

thanglq1 commented May 8, 2024

Yes, my bad. I forgot change this. So will close this issue.

var color = editorKey.currentState?.paintingEditor
                                        .currentState?.paintMode ==
                                    item.mode
                                ? imageEditorPrimaryColor
                                : const Color(0xFFEEEEEE);

@thanglq1 thanglq1 closed this as completed May 8, 2024
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
Development

No branches or pull requests

2 participants