@@ -195,6 +195,30 @@ Widget buildFrame({
195
195
);
196
196
}
197
197
198
+ Widget buildDropdownWithHint ({
199
+ required AlignmentDirectional alignment,
200
+ required bool isExpanded,
201
+ bool enableSelectedItemBuilder = false ,
202
+ }){
203
+ return buildFrame (
204
+ mediaSize: const Size (800 , 600 ),
205
+ itemHeight: 100.0 ,
206
+ alignment: alignment,
207
+ isExpanded: isExpanded,
208
+ selectedItemBuilder: enableSelectedItemBuilder
209
+ ? (BuildContext context) {
210
+ return menuItems.map <Widget >((String item) {
211
+ return Container (
212
+ color: const Color (0xff00ff00 ),
213
+ child: Text (item),
214
+ );
215
+ }).toList ();
216
+ }
217
+ : null ,
218
+ hint: const Text ('hint' ),
219
+ );
220
+ }
221
+
198
222
class TestApp extends StatefulWidget {
199
223
const TestApp ({
200
224
super .key,
@@ -3657,155 +3681,225 @@ void main() {
3657
3681
});
3658
3682
3659
3683
testWidgets ('DropdownButton hint alignment' , (WidgetTester tester) async {
3660
- final Key buttonKey = UniqueKey ();
3661
3684
const String hintText = 'hint' ;
3662
3685
3663
- // DropdownButton with `isExpanded: false` (default)
3664
3686
// AlignmentDirectional.centerStart (default)
3665
- await tester.pumpWidget (buildFrame (
3666
- buttonKey: buttonKey,
3667
- mediaSize: const Size (800 , 600 ),
3668
- itemHeight: 100.0 ,
3669
- hint: const Text (hintText)),
3670
- );
3687
+ await tester.pumpWidget (buildDropdownWithHint (
3688
+ alignment: AlignmentDirectional .centerStart,
3689
+ isExpanded: false ,
3690
+ ));
3671
3691
expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3672
3692
expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3673
3693
// AlignmentDirectional.topStart
3674
- await tester.pumpWidget (buildFrame (
3675
- buttonKey: buttonKey,
3676
- mediaSize: const Size (800 , 600 ),
3694
+ await tester.pumpWidget (buildDropdownWithHint (
3677
3695
alignment: AlignmentDirectional .topStart,
3678
- itemHeight: 100.0 ,
3679
- hint: const Text (hintText)),
3680
- );
3696
+ isExpanded: false ,
3697
+ ));
3681
3698
expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3682
3699
expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3683
3700
// AlignmentDirectional.bottomStart
3684
- await tester.pumpWidget (buildFrame (
3685
- buttonKey: buttonKey,
3686
- mediaSize: const Size (800 , 600 ),
3701
+ await tester.pumpWidget (buildDropdownWithHint (
3687
3702
alignment: AlignmentDirectional .bottomStart,
3688
- itemHeight: 100.0 ,
3689
- hint: const Text (hintText)),
3690
- );
3703
+ isExpanded: false ,
3704
+ ));
3691
3705
expect (tester.getBottomLeft (find.text (hintText)).dx, 348.0 );
3692
3706
expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3693
3707
// AlignmentDirectional.center
3694
- await tester.pumpWidget (buildFrame (
3695
- buttonKey: buttonKey,
3696
- mediaSize: const Size (800 , 600 ),
3708
+ await tester.pumpWidget (buildDropdownWithHint (
3697
3709
alignment: AlignmentDirectional .center,
3698
- itemHeight: 100.0 ,
3699
- hint: const Text (hintText)),
3700
- );
3710
+ isExpanded: false ,
3711
+ ));
3701
3712
expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3702
3713
expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3703
3714
// AlignmentDirectional.topEnd
3704
- await tester.pumpWidget (buildFrame (
3705
- buttonKey: buttonKey,
3706
- mediaSize: const Size (800 , 600 ),
3715
+ await tester.pumpWidget (buildDropdownWithHint (
3707
3716
alignment: AlignmentDirectional .topEnd,
3708
- itemHeight: 100.0 ,
3709
- hint: const Text (hintText)),
3710
- );
3717
+ isExpanded: false ,
3718
+ ));
3711
3719
expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3712
3720
expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3713
3721
// AlignmentDirectional.centerEnd
3714
- await tester.pumpWidget (buildFrame (
3715
- buttonKey: buttonKey,
3716
- mediaSize: const Size (800 , 600 ),
3722
+ await tester.pumpWidget (buildDropdownWithHint (
3717
3723
alignment: AlignmentDirectional .centerEnd,
3718
- itemHeight: 100.0 ,
3719
- hint: const Text (hintText)),
3720
- );
3724
+ isExpanded: false ,
3725
+ ));
3721
3726
expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3722
3727
expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3723
- // AlignmentDirectional.topEnd
3724
- await tester.pumpWidget (buildFrame (
3725
- buttonKey: buttonKey,
3726
- mediaSize: const Size (800 , 600 ),
3728
+ // AlignmentDirectional.bottomEnd
3729
+ await tester.pumpWidget (buildDropdownWithHint (
3727
3730
alignment: AlignmentDirectional .bottomEnd,
3728
- itemHeight: 100.0 ,
3729
- hint: const Text (hintText)),
3730
- );
3731
+ isExpanded: false ,
3732
+ ));
3731
3733
expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3732
3734
expect (tester.getTopRight (find.text (hintText)).dy, 334.0 );
3733
3735
3734
3736
// DropdownButton with `isExpanded: true`
3735
3737
// AlignmentDirectional.centerStart (default)
3736
- await tester.pumpWidget (buildFrame (
3737
- buttonKey: buttonKey,
3738
- mediaSize: const Size (800 , 600 ),
3739
- itemHeight: 100.0 ,
3738
+ await tester.pumpWidget (buildDropdownWithHint (
3739
+ alignment: AlignmentDirectional .centerStart,
3740
3740
isExpanded: true ,
3741
- hint: const Text (hintText)),
3742
- );
3741
+ ));
3743
3742
expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3744
3743
expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3745
3744
// AlignmentDirectional.topStart
3746
- await tester.pumpWidget (buildFrame (
3747
- buttonKey: buttonKey,
3748
- mediaSize: const Size (800 , 600 ),
3749
- itemHeight: 100.0 ,
3750
- isExpanded: true ,
3745
+ await tester.pumpWidget (buildDropdownWithHint (
3751
3746
alignment: AlignmentDirectional .topStart,
3752
- hint : const Text (hintText)) ,
3753
- );
3747
+ isExpanded : true ,
3748
+ )) ;
3754
3749
expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3755
3750
expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3756
3751
// AlignmentDirectional.bottomStart
3757
- await tester.pumpWidget (buildFrame (
3758
- buttonKey: buttonKey,
3759
- mediaSize: const Size (800 , 600 ),
3760
- itemHeight: 100.0 ,
3761
- isExpanded: true ,
3752
+ await tester.pumpWidget (buildDropdownWithHint (
3762
3753
alignment: AlignmentDirectional .bottomStart,
3763
- hint : const Text (hintText)) ,
3764
- );
3754
+ isExpanded : true ,
3755
+ )) ;
3765
3756
expect (tester.getBottomLeft (find.text (hintText)).dx, 0.0 );
3766
3757
expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3767
3758
// AlignmentDirectional.center
3768
- await tester.pumpWidget (buildFrame (
3769
- buttonKey: buttonKey,
3770
- mediaSize: const Size (800 , 600 ),
3771
- itemHeight: 100.0 ,
3759
+ await tester.pumpWidget (buildDropdownWithHint (
3760
+ alignment: AlignmentDirectional .center,
3772
3761
isExpanded: true ,
3762
+ ));
3763
+ expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3764
+ expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3765
+ // AlignmentDirectional.topEnd
3766
+ await tester.pumpWidget (buildDropdownWithHint (
3767
+ alignment: AlignmentDirectional .topEnd,
3768
+ isExpanded: true ,
3769
+ ));
3770
+ expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3771
+ expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3772
+ // AlignmentDirectional.centerEnd
3773
+ await tester.pumpWidget (buildDropdownWithHint (
3774
+ alignment: AlignmentDirectional .centerEnd,
3775
+ isExpanded: true ,
3776
+ ));
3777
+ expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3778
+ expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3779
+ // AlignmentDirectional.bottomEnd
3780
+ await tester.pumpWidget (buildDropdownWithHint (
3781
+ alignment: AlignmentDirectional .bottomEnd,
3782
+ isExpanded: true ,
3783
+ ));
3784
+ expect (tester.getBottomRight (find.text (hintText)).dx, 776.0 );
3785
+ expect (tester.getBottomRight (find.text (hintText)).dy, 350.0 );
3786
+ });
3787
+
3788
+ testWidgets ('DropdownButton hint alignment with selectedItemBuilder' , (WidgetTester tester) async {
3789
+ const String hintText = 'hint' ;
3790
+
3791
+ // AlignmentDirectional.centerStart (default)
3792
+ await tester.pumpWidget (buildDropdownWithHint (
3793
+ alignment: AlignmentDirectional .centerStart,
3794
+ isExpanded: false ,
3795
+ enableSelectedItemBuilder: true ,
3796
+ ));
3797
+ expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3798
+ expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3799
+ // AlignmentDirectional.topStart
3800
+ await tester.pumpWidget (buildDropdownWithHint (
3801
+ alignment: AlignmentDirectional .topStart,
3802
+ isExpanded: false ,
3803
+ enableSelectedItemBuilder: true ,
3804
+ ));
3805
+ expect (tester.getTopLeft (find.text (hintText)).dx, 348.0 );
3806
+ expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3807
+ // AlignmentDirectional.bottomStart
3808
+ await tester.pumpWidget (buildDropdownWithHint (
3809
+ alignment: AlignmentDirectional .bottomStart,
3810
+ isExpanded: false ,
3811
+ enableSelectedItemBuilder: true ,
3812
+ ));
3813
+ expect (tester.getBottomLeft (find.text (hintText)).dx, 348.0 );
3814
+ expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3815
+ // AlignmentDirectional.center
3816
+ await tester.pumpWidget (buildDropdownWithHint (
3773
3817
alignment: AlignmentDirectional .center,
3774
- hint: const Text (hintText)),
3775
- );
3818
+ isExpanded: false ,
3819
+ enableSelectedItemBuilder: true ,
3820
+ ));
3776
3821
expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3777
3822
expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3778
3823
// AlignmentDirectional.topEnd
3779
- await tester.pumpWidget (buildFrame (
3780
- buttonKey: buttonKey,
3781
- mediaSize: const Size (800 , 600 ),
3782
- itemHeight: 100.0 ,
3824
+ await tester.pumpWidget (buildDropdownWithHint (
3825
+ alignment: AlignmentDirectional .topEnd,
3826
+ isExpanded: false ,
3827
+ enableSelectedItemBuilder: true ,
3828
+ ));
3829
+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3830
+ expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3831
+ // AlignmentDirectional.centerEnd
3832
+ await tester.pumpWidget (buildDropdownWithHint (
3833
+ alignment: AlignmentDirectional .centerEnd,
3834
+ isExpanded: false ,
3835
+ enableSelectedItemBuilder: true ,
3836
+ ));
3837
+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3838
+ expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3839
+ // AlignmentDirectional.bottomEnd
3840
+ await tester.pumpWidget (buildDropdownWithHint (
3841
+ alignment: AlignmentDirectional .bottomEnd,
3842
+ isExpanded: false ,
3843
+ enableSelectedItemBuilder: true ,
3844
+ ));
3845
+ expect (tester.getTopRight (find.text (hintText)).dx, 428.0 );
3846
+ expect (tester.getTopRight (find.text (hintText)).dy, 334.0 );
3847
+
3848
+ // DropdownButton with `isExpanded: true`
3849
+ // AlignmentDirectional.centerStart (default)
3850
+ await tester.pumpWidget (buildDropdownWithHint (
3851
+ alignment: AlignmentDirectional .centerStart,
3852
+ isExpanded: true ,
3853
+ enableSelectedItemBuilder: true ,
3854
+ ));
3855
+ expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3856
+ expect (tester.getTopLeft (find.text (hintText)).dy, 292.0 );
3857
+ // AlignmentDirectional.topStart
3858
+ await tester.pumpWidget (buildDropdownWithHint (
3859
+ alignment: AlignmentDirectional .topStart,
3860
+ isExpanded: true ,
3861
+ enableSelectedItemBuilder: true ,
3862
+ ));
3863
+ expect (tester.getTopLeft (find.text (hintText)).dx, 0.0 );
3864
+ expect (tester.getTopLeft (find.text (hintText)).dy, 250.0 );
3865
+ // AlignmentDirectional.bottomStart
3866
+ await tester.pumpWidget (buildDropdownWithHint (
3867
+ alignment: AlignmentDirectional .bottomStart,
3868
+ isExpanded: true ,
3869
+ enableSelectedItemBuilder: true ,
3870
+ ));
3871
+ expect (tester.getBottomLeft (find.text (hintText)).dx, 0.0 );
3872
+ expect (tester.getBottomLeft (find.text (hintText)).dy, 350.0 );
3873
+ // AlignmentDirectional.center
3874
+ await tester.pumpWidget (buildDropdownWithHint (
3875
+ alignment: AlignmentDirectional .center,
3783
3876
isExpanded: true ,
3877
+ enableSelectedItemBuilder: true ,
3878
+ ));
3879
+ expect (tester.getCenter (find.text (hintText)).dx, 388.0 );
3880
+ expect (tester.getCenter (find.text (hintText)).dy, 300.0 );
3881
+ // AlignmentDirectional.topEnd
3882
+ await tester.pumpWidget (buildDropdownWithHint (
3784
3883
alignment: AlignmentDirectional .topEnd,
3785
- hint: const Text (hintText)),
3786
- );
3884
+ isExpanded: true ,
3885
+ enableSelectedItemBuilder: true ,
3886
+ ));
3787
3887
expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3788
3888
expect (tester.getTopRight (find.text (hintText)).dy, 250.0 );
3789
3889
// AlignmentDirectional.centerEnd
3790
- await tester.pumpWidget (buildFrame (
3791
- buttonKey: buttonKey,
3792
- mediaSize: const Size (800 , 600 ),
3793
- itemHeight: 100.0 ,
3794
- isExpanded: true ,
3890
+ await tester.pumpWidget (buildDropdownWithHint (
3795
3891
alignment: AlignmentDirectional .centerEnd,
3796
- hint: const Text (hintText)),
3797
- );
3892
+ isExpanded: true ,
3893
+ enableSelectedItemBuilder: true ,
3894
+ ));
3798
3895
expect (tester.getTopRight (find.text (hintText)).dx, 776.0 );
3799
3896
expect (tester.getTopRight (find.text (hintText)).dy, 292.0 );
3800
3897
// AlignmentDirectional.bottomEnd
3801
- await tester.pumpWidget (buildFrame (
3802
- buttonKey: buttonKey,
3803
- mediaSize: const Size (800 , 600 ),
3804
- itemHeight: 100.0 ,
3805
- isExpanded: true ,
3898
+ await tester.pumpWidget (buildDropdownWithHint (
3806
3899
alignment: AlignmentDirectional .bottomEnd,
3807
- hint: const Text (hintText)),
3808
- );
3900
+ isExpanded: true ,
3901
+ enableSelectedItemBuilder: true ,
3902
+ ));
3809
3903
expect (tester.getBottomRight (find.text (hintText)).dx, 776.0 );
3810
3904
expect (tester.getBottomRight (find.text (hintText)).dy, 350.0 );
3811
3905
});
0 commit comments