Code Monkey home page Code Monkey logo

frezyx / group_button Goto Github PK

View Code? Open in Web Editor NEW
285.0 4.0 44.0 26.14 MB

:sweat_drops: Flutter custom widget to make a group buttons. Included Radio and CheckBox buttons.

Home Page: https://pub.dev/packages/group_button

License: MIT License

Kotlin 0.11% Swift 0.94% Objective-C 0.03% Dart 62.60% Makefile 0.08% HTML 1.49% CMake 15.20% C++ 18.39% C 1.16%
button flutter dart flutter-button group buttons buttons-collection flutter-widget flutter-widgets widget

group_button's Issues

Button text padding has a gap on top

Hello,

Finally, I got the solution for. this bug, but trying to make the text fit to my button i got this problem: It is a gap on the top padding, if we put a simetrical padding for vertical, the text will be more to bottom than top.

To fix this i hade to user a custom padding:
Screen Shot 2021-12-09 at 17 35 50

As you can see in the picture, I had to put less padding for top.

I'm having problems with the padding now:
Screen Shot 2021-12-13 at 22 05 00
You can see here how with short text we have problems on top, leading us to understand, the padding is wrong only on long texts.

Now, when we remove the padding or we make padding same for every, we will get the next problems.
Screen Shot 2021-12-13 at 22 08 21
Screen Shot 2021-12-13 at 22 09 26
Screen Shot 2021-12-13 at 22 10 03

Why does this happen?

Thanks

When isRadio is true it starts with first button selected

When I user isRadio=true I expect the options to be rendered with all button unselected. That would match how radio buttons work in HTML for example.

Right now, the first option is selected. In the example below, button A is selected automatically.

GroupButton(
            isRadio: true,
            spacing: 10,
            onSelected: (index, isSelected) => setState(
                () => choiceSelectionOutput = widget.optionsOutputText[index]),
            buttons: ["A","B", "C"]
        )

Border width

Hiya,

Fantastic package, thank you!
One thing it's missing for me is the ability to specify the width of the button border. I've had to use a buttonBuilder to recreate all the other properties of a default GroupButton, but add the border width. Because of this, I lose the InkWell type splash effect.

Please add an option from which we can choose classic/regular/old Radio and Checkbox .

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

_GroupButtonBodyState.initState() minor bug

class _GroupButtonBodyState extends State<GroupButtonBody> {
  @override
  void initState() {
    super.initState();

    if (!widget.isRadio) {
      widget.controller.toggleIndexes(widget.selectedButtons ?? []); // <<< has to be selectIndexes
    }

Because the following code is not working properly:

GroupButton(
  selectedButtons: selected,
  controller: GroupButtonController()..selectIndexes(selected),

It's oversimplified example, the point is that you cannot set properly synchronized selectedButtons and controller.

Enhancement thought for using with Bloc...

Hi, this is more an enhancement thought than an Issue.
I am using this package in an app that is using Bloc.. Specifically as a piece of a form using flutter_form_bloc.
I ran into an issue where if the state of the selection is changed by bloc, then the widget doesn't update.. In my use case, the form can be loaded from a web query, so the initial sate of the form might be updated externally by bloc.

To solve this for me I added the following to the _GroupButtonBodyState to allow for the widget to update..

  @override
  void didUpdateWidget(Widget OldWidget) {
    for (var i = 0; i < widget.buttons.length; i++) {
      if (widget.selectedButtons!.contains(i)) {
        _selectedIndexes[i] = true;
      } else {
        _selectedIndexes[i] = false;
      }
    }
    setState(() {});
  }

I realize this doesn't cover the radio Button case, but I wasn't using that format for my use case.
I'm still learning Flutter so this may not be the best way to do this.
I'm not sure if this is an enhancement you may want to include in some form, I just thought I'd pass on my use case.
Thanks for the great package.

Consider adding onChage method with button values

It would be great to have the api that allows setting selected buttons not by index but with actual buttons values.
For example while using in forms

Also it would be great to have onChange method with selected button values

How to have buttons take up available parent width

This is more of a question - but I am placing a GroupButton with two buttons in an Expanded inside of a row, and I expected them to automatically fill out the available width of the Expanded widget but they don't.

How can I do this? I don't want to have to explicitly set the button widths.

Centering button on vertical direction.

Hello again,

This package is so good, we got used to it and we like to work with it.

We just have a single suggestion for styling:
image

As you can see, in vertical direction not all buttons are properly centered, it would be great to have them centered by default, or optionally centered.

What do you think?

Question: Horizontal scrolling GroupButton (e.g. for creating "quick search buttons")

I'm trying to add "quick search buttons" to my flutter app like (in red):

image

This packages looks great for the button part of this, but I'm struggling to make the GroupButton horizontal scrollable. I can achieve this using a ListView.separated, e.g. (from https://stackoverflow.com/a/71386591/5179470)

ListView.separated(
                itemCount: fruits.length,
                scrollDirection: Axis.horizontal,
                itemBuilder: (context, index) => FilterChip(
                  label: Text(fruits[index]),
                  selected: index == selectedIndex,
                  onSelected: (value) {
                    setState(() {
                      selectedIndex = index;
                    });
                  },
                ),

but I can't seem to get a GroupButton to work with this. This issue looks related: #21 (mentioning @YouSour in case they have got it to work).

Many thanks for any help, and for this amazing lib!! :)

Cannot dynamically change the selected button

GroupButton(
spacing: 10.w,
isRadio: true,
buttons: _tabValues,
onSelected: _onTabbarTap,
### selectedButton: _tabbarIndex,
)

setState(() {
_tabbarIndex = index;
});

It's doesn't work!, How can I do?

Default GroupButtonController must be created in _GroupButtonBodyState

The following code is wrong, because it leads to default GroupButtonController rebuild on every GroupButton.build(), so I have to always pass external GroupButtonController to GroupButton constructor.

return GroupButtonBody(
  ...
  controller: controller ?? GroupButtonController(),
);

The right code should be like this:

class _GroupButtonBodyState extends State<GroupButtonBody> {
  GroupButtonController _controller = widget.controller ?? GroupButtonController();

  @override
  void didUpdateWidget(covariant GroupButtonBody oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (oldWidget.controller != widget.controller) _controller = widget.controller ?? GroupButtonController();  
  }

Disabled buttons

It would be nice to add disabled buttons functionality similar to existing selectedButtons, like:
disabledButtons: const [2, 3],

No named parameter with the name 'primary'.

Describe the bug
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-000210183AFA401E }
{ platform:macOS, arch:x86_64, id:00006000-000210183AFA401E }
../../.pub-cache/hosted/pub.flutter-io.cn/group_button-5.3.3/lib/src/group_button_item.dart:92:9: Error: No named parameter with the name 'primary'.
primary: _getBackgroundColor(theme),
^^^^^^^
../../flutter/packages/flutter/lib/src/material/elevated_button.dart:151:22: Context: Found this candidate, but the arguments don't match.
static ButtonStyle styleFrom({
^^^^^^^^^
Target kernel_snapshot failed: Exception

Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

To Reproduce
Steps to reproduce the behavior:
flutter build macos

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macos
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]
  • flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel master, 3.18.0-11.0.pre.74, on macOS 14.2 23C64 darwin-arm64, locale zh-Hans-CN)
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2022.3)
    [✓] VS Code (version 1.82.2)
    [✓] VS Code (version 1.85.0)
    [✓] Connected device (2 available)
    [✓] Network resources

• No issues found!

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

group_button_item.dart:91:9: Error: No named parameter with the name 'backgroundColor'. backgroundColor: _getBackgroundColor(theme), ^^^^^^^^^^^^^^^

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Adding event on disabled items

i think adding event on disabled items developers may need it (i need it 😸), for exemple if item is disable and user click on it may i need to show a toast message like "This feature is coming soon" or "This feature are availble only for 18+ age"... what do you think ?

Não consigo recuperar o valor da opção selecionada...

Após eu ter selecionada uma das opções possíveis, não consegui descobrir como saber QUAL foi o botão selecionado, pois no código exemplo que vc mencionou faltou constar COMO identificar qual opção foi selecionada.

Segue abaixo meu código simples (a pessoa deve informar seu SEXO).

GroupButton(
isRadio: true,
onSelected: (index, isSelected) => print('$index button is selected'),
buttons: ["Sou HOMEM", "Sou MULHER"],
),
),

Após a pessoa ter feita sua escolha, como eu consigo saber em meu aplicativo qual botão foi selecionado? Podes dar-me um exemplo de como seria o código para mostrar qual foi o botão selecionado?

Agradecido... :-D

Spacing should be required

Using this package to build our questionary app we got the next bug:

======== Exception caught by widgets library =======================================================
The following _CastError was thrown building GroupButtonBody(dirty, dependencies: [_InheritedProviderScope<GroupButtonBloc>]):
Null check operator used on a null value

The relevant error-causing widget was: 
  GroupButton file:///home/luisalaguna/Projects/thesis_cancer/lib/features/survey/presentation/widgets/question_widget.dart:67:24
When the exception was thrown, this was the stack: 
#0      GroupButtonBody.build (package:group_button/src/group_button_body.dart:55:23)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4569:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
#4      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4474:5)
...

Screenshot_player_20210420112444

My code is this one:

case QuestionType.BOOL:
        answerWidget = GroupButton(
          buttons: ['Yanlış', 'Doğru'],
          onSelected: (index, isSelected) => print('$index button is selected'),
          direction: Axis.vertical,
        );
        break;

Debugging superficially over this bug we found the next:
Screenshot_select-area_20210420113916

It seems in some cases the spacing parameter is required, but it is that in all, to build the widget correctly; adding it to my code make it works correctly.

Hence, We think this parameter would be required or would have a default value.

Thanks.

Consider api deduplication

Currently package has
selectedButton
selectedButtons

also has
_selectedIndexes
_selectedIndex

Consider simplifying the api to be more generic.
In case of isRadio the _selectedIndexes could be limited to only one item - this will simplifies the api and internal logic

selectedButtons

Hi ,we cant run without any button selected ?
i need when page load after no selection any buttons

Row buttons count

Will be nice to have options with count mentioned per row. Something like this:
options: GroupButtonOptions( groupingType: GroupingType.row, count: 10, ),

Currently we are getting RenderFlex overflowed by pixels on the right error. Would be nice if this lib has this feature.

Fit long text to the screen width

Thank you for your package, it is amazing, but we got this issue:
Screen Shot 2021-12-09 at 00 29 01

Text are so long it is not rendered properly, do you have any idea about to solve it?

Thank you

"Old school" style.

Hi, thanks for this good alternative that can fulfill our needs.

I'm working on reproduce this questionary application, and I'm using this package as an alternative to grouped_buttons.

I would like to know if it is possible to get the oldschool style for checkbox(box) and radio buttons whit this package.

is there any way to do it with the current state of the package? Does it require a new feature?

Thank you very much.

Unselect group button

Is there a way to unselect the buttons inside the group button?

I have tried to set the selectedButton to null but it's not working,

Deselect stops working when controller is added

Hi, thanks for a great plugin.

I use it in a custom FormBuilderField, and needed a way to initialize selected buttons. It wasn't obvious how to set init values, but eventually I made it by adding GroupButtonController. All worked well until I discovered that deselecting buttons stopped working.

If I remove controller, deselecting works again (but no way to set init values).

Any hints on what can be wrong? Is it a bug or I'm doing something wrong? (maybe there is a way to preselect buttons without controller?)

SelectedButtons is not getting the correct selected button

I'm trying to make a form using this package and Riverpod.

Right now i'm trying to keep the button selected between different groups, but it does not:
image
As you can see, both different questions can have different values, and they are saved, but when i try to keep each one for each question, both widgets keeps the same selected value:
Record_player_20210420201527
It seems to keep the same index ever, as if always it would be the same widget, what is we don't want.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.