-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add SegmentedButton.styleFrom
#137542
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
Add SegmentedButton.styleFrom
#137542
Conversation
|
hi, @TahaTesser #137430 in this pr you gave me suggestions. l followed them. but l took errors again. l could not understand sorry. |
|
it seems there are a bunch of errors in this PR. Can you please take a look at the errors and fix them? |
|
Hi, @TahaTesser probably mission completed :) |
|
@AcarFurkan |
|
Can you please link an issue this PR fixes? If it doesn't exist, please file an issue and link it in the PR description. |
|
#138289 This is a feature request and I'm adding it. |
packages/flutter/test/material/segmented_button_theme_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter/test/material/segmented_button_theme_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter/test/material/segmented_button_theme_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter/test/material/segmented_button_theme_test.dart
Outdated
Show resolved
Hide resolved
|
Looks like current tests are just duplications and not necessarily testing |
|
You asked me for a test for this in another thread, so I added all the tests. |
Since this is one of your first PRs. I'm writing tests for you. i will comment it soon. |
|
Oh thank you so much, I can help you if you give me a clue. |
TahaTesser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With my suggestions applied and after adding SegmentedButton.styleFrom specific test this looks ready
LGTM!
|
@TahaTesser This is my first contribution to flutter, what do you think? And thank you so much for your concern :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to review this carefully yet but at first blush it looks good. Can you include the example (and an example test)? The calendar example you've provided should work although you might want to configure a pair of of foo/disabledFoo properties just to amplify the idea.
|
hi @HansMuller, I'm sorry I didn't understand exactly what you wanted. I added such an example. |
|
@AcarFurkan It doesn't look necessary. The test added is sufficient to test |
|
hans said "Can you include the example (and an example test)?" l don't understand actually what he wants. if you want l can remove |
|
hi @TahaTesser if you understand, can you explain what he wants? l added an example is it enough |
Feel free to ask. The test you added is a duplication of the existing, without any relevance. Hans asked if you can add example and example test (not the widget test). |
|
You should be able to use |
|
awesome let's wait then @TahaTesser thanks for everything :) |
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, just some minor feedback.
examples/api/lib/material/segmented_button/segmented_button.1.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this have been written in terms of ButtonStyle.styleFrom()? If there are any differences you could write something like return ButtonStyle.styleFrom(...).copyWith(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AcarFurkan seems to be lost so I've addressed this feedback.
Added TextButton.styleFrom with .copyWith for background, foreground, and overlay color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good idea to duplicate aspects of _M3Defaults here; we want this stuff to change automatically when we regenerate _M3Defaults. Adding methods to the _M3Defaults template is OK. When you do be sure to explain the use cases in comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I added a static function in _M3Defaults which uses the tokens to return color with opacity in the selected and unselected states.
|
@AcarFurkan |
|
I solved 4 of them, but I couldn't understand the remaining 2. @HansMuller If you have the time, can you give some details for the 2 that I can't figure out? |
|
@TahaTesser @HansMuller hii, I know you are very busy and I am sorry to bother you, but there are two feedbacks that I cannot solve, if you can explain them, I will solve them. I would be very happy if you get back to me when you are available. thank you :) |
Revert "added SegmentedButton.stylefrom to SegmentedButton" This reverts commit 34b8696ad759bef8ab577b9751e86b4f342c3acf. reverted commit and fix string problems Refactor: deleting custom deprecated messages Update packages/flutter/lib/src/material/segmented_button.dart update documentation Co-authored-by: Taha Tesser <[email protected]> Update packages/flutter/lib/src/material/segmented_button.dart remove unnecessary explanations from the documentation Co-authored-by: Taha Tesser <[email protected]> Update packages/flutter/lib/src/material/segmented_button.dart Co-authored-by: Taha Tesser <[email protected]> Update packages/flutter/lib/src/material/segmented_button.dart update _SegmentedButtonDefaultElevation to MaterialStatePropertyAll<double> Co-authored-by: Taha Tesser <[email protected]> Update packages/flutter/lib/src/material/segmented_button.dart delete unnecessary empty lines Co-authored-by: Taha Tesser <[email protected]> Update packages/flutter/lib/src/material/segmented_button.dart Co-authored-by: Taha Tesser <[email protected]> Refactor: changing overlay opacity values according to m3 Update packages/flutter/lib/src/material/segmented_button.dart Update packages/flutter/test/material/segmented_button_theme_test.dart Update packages/flutter/test/material/segmented_button_theme_test.dart Update packages/flutter/test/material/segmented_button_theme_test.dart Update packages/flutter/test/material/segmented_button_theme_test.dart Update packages/flutter/lib/src/material/segmented_button.dart Update packages/flutter/lib/src/material/segmented_button.dart Update packages/flutter/lib/src/material/segmented_button.dart Update packages/flutter/lib/src/material/segmented_button.dart Add test add test for multi selection Update packages/flutter/test/material/segmented_button_test.dart style added to segmented_button example and added test to segmented button added license header buttonStyle instance moved to outside of button widget moving example and test to right file Refactor: minimize example Update packages/flutter/lib/src/material/segmented_button.dart Co-authored-by: Taha Tesser <[email protected]> Update examples/api/lib/material/segmented_button/segmented_button.1.dart Co-authored-by: Taha Tesser <[email protected]> Update examples/api/lib/material/segmented_button/segmented_button.1.dart Co-authored-by: Taha Tesser <[email protected]> Fix example and update test Fix documentation Update examples/api/lib/material/segmented_button/segmented_button.1.dart Co-authored-by: Hans Muller <[email protected]> Refactor: adding tool snippet Refactor: example link added Refactor: shortened the example Refactor: ButtonStyle updated to ButtonStyle.styleFrom Refactor: Buttonstyle.from json to Buttonstyle
Address comments
|
@HansMuller Please take a look the address review commit c690ee1 |
Your changes LGTM. This PR appears to be ready to land. |
TahaTesser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
HansMuller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Manual roll Flutter from 11def8e to cc40425 (118 revisions) Manual roll requested by [email protected] flutter/flutter@11def8e...cc40425 2024-01-05 [email protected] Roll Flutter Engine from 0bbb4d61ce82 to f60d9a9a3395 (1 revision) (flutter/flutter#140993) 2024-01-04 [email protected] Roll Flutter Engine from b2a9ce88a19e to 0bbb4d61ce82 (3 revisions) (flutter/flutter#140990) 2024-01-04 [email protected] [web] Fix and unskip a few more CanvasKit tests (flutter/flutter#140821) 2024-01-04 [email protected] Roll Flutter Engine from bd175aa5e0b6 to b2a9ce88a19e (1 revision) (flutter/flutter#140986) 2024-01-04 [email protected] Pin package:vm_service (flutter/flutter#140972) 2024-01-04 [email protected] Add scrollbar for menus (flutter/flutter#140941) 2024-01-04 [email protected] manual pub roll to pick up dds fixes (flutter/flutter#140979) 2024-01-04 [email protected] Roll Flutter Engine from b81023eb71c9 to bd175aa5e0b6 (2 revisions) (flutter/flutter#140980) 2024-01-04 [email protected] Temporarily remove env variable for leak tracking bots. (flutter/flutter#140978) 2024-01-04 [email protected] Add Flutter CI status to README (flutter/flutter#140513) 2024-01-04 [email protected] Reland "integrate testWidgets with leak tracking" (#140521) (flutter/flutter#140928) 2024-01-04 [email protected] Run half of iOS devicelab tests with Xcode 15 (flutter/flutter#140927) 2024-01-04 [email protected] Fix `SegmentedButton` states update logic (flutter/flutter#140772) 2024-01-04 [email protected] Roll Flutter Engine from f539acfb8c5a to b81023eb71c9 (1 revision) (flutter/flutter#140973) 2024-01-04 [email protected] [Fix] Consistency in ButtonStyleButton related Tests (flutter/flutter#140610) 2024-01-04 [email protected] Roll Packages from bbb4134 to 31fc7b5 (6 revisions) (flutter/flutter#140967) 2024-01-04 [email protected] Fix local engine use in macOS plugins (flutter/flutter#140222) 2024-01-04 [email protected] Roll Flutter Engine from 7d5a120a601b to f539acfb8c5a (2 revisions) (flutter/flutter#140959) 2024-01-04 [email protected] Roll Flutter Engine from 1ff3cb885842 to 7d5a120a601b (1 revision) (flutter/flutter#140946) 2024-01-04 [email protected] Roll Flutter Engine from c8bf51f0d4cd to 1ff3cb885842 (1 revision) (flutter/flutter#140943) 2024-01-04 [email protected] Roll Flutter Engine from bfd2d8a100ec to c8bf51f0d4cd (2 revisions) (flutter/flutter#140939) 2024-01-04 [email protected] Roll Flutter Engine from 28ae9e35c331 to bfd2d8a100ec (1 revision) (flutter/flutter#140937) 2024-01-04 [email protected] Roll Flutter Engine from ab4098c742f8 to 28ae9e35c331 (1 revision) (flutter/flutter#140936) 2024-01-04 [email protected] Roll Flutter Engine from e169f3677008 to ab4098c742f8 (2 revisions) (flutter/flutter#140933) 2024-01-03 [email protected] Roll Flutter Engine from 7c2adb811059 to e169f3677008 (1 revision) (flutter/flutter#140929) 2024-01-03 [email protected] Remove deprecated bitcode stripping from tooling (flutter/flutter#140903) 2024-01-03 [email protected] Add Windows leak tracking targets (flutter/flutter#140423) 2024-01-03 [email protected] [github actions] refactor and fix cherry pick actions (flutter/flutter#140499) 2024-01-03 [email protected] Migrate Xcode projects last version checks to Xcode 15.1 (flutter/flutter#140256) 2024-01-03 [email protected] Roll Flutter Engine from bf232c4da241 to 7c2adb811059 (3 revisions) (flutter/flutter#140920) 2024-01-03 [email protected] fix typo and reflow (flutter/flutter#140925) 2024-01-03 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Re-land integrate testWidgets with leak tracking." (flutter/flutter#140926) 2024-01-03 [email protected] Roll Flutter Engine from bf979d220283 to bf232c4da241 (1 revision) (flutter/flutter#140915) 2024-01-03 [email protected] Changes the regular cursor to a floating cursor when a long press occurs. (flutter/flutter#138479) 2024-01-03 [email protected] Add `SegmentedButton.styleFrom` (flutter/flutter#137542) 2024-01-03 [email protected] Roll Flutter Engine from c62bcff5b809 to bf979d220283 (1 revision) (flutter/flutter#140910) 2024-01-03 [email protected] Re-land integrate testWidgets with leak tracking. (flutter/flutter#140521) 2024-01-03 [email protected] Roll Flutter Engine from 98b72c7ffe71 to c62bcff5b809 (2 revisions) (flutter/flutter#140905) 2024-01-03 [email protected] [flutter_tools] add support for --enable-impeller to test device. (flutter/flutter#140899) 2024-01-03 [email protected] Roll Flutter Engine from cf7536964a2f to 98b72c7ffe71 (1 revision) (flutter/flutter#140897) 2024-01-03 [email protected] Handle KEYCODE_DPAD_CENTER and KEYCODE_ENTER (flutter/flutter#140808) 2024-01-03 [email protected] Add Lucas Saudon to AUTHORS (flutter/flutter#139965) 2024-01-03 [email protected] Link to wiki page about updating dependencies in each `pubspec.yaml` file (flutter/flutter#140826) 2024-01-03 [email protected] Marks Linux_pixel_7pro native_assets_android to be unflaky (flutter/flutter#140866) ... --------- Co-authored-by: Tarrin Neal <[email protected]>

fixes #138289
SegmentedButtom.styleFrom has been added to the segment button, so there is no longer any need to the button style from the beginning. It works like ElevatedButton.styleFrom only I added selectedForegroundColor, selectedBackgroundColor. In this way, the user will be able to change the color first without checking the MaterialState states. I added tests of the same controls.
#129215 I opened this problem myself, but I was rejected because I handled too many items in a PR. For now, I wrote a structure that only handles MaterialStates instead of users.
old (still avaliable)

new (just an option for developer)

Code sample
expand to view the code sample
Pre-launch Checklist
///).