2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'package:flutter/gestures.dart' ;
5
6
import 'package:flutter/material.dart' ;
6
7
import 'package:flutter/rendering.dart' ;
7
8
import 'package:flutter/services.dart' ;
@@ -16,6 +17,7 @@ TextStyle? _iconStyle(WidgetTester tester, IconData icon) {
16
17
);
17
18
return iconRichText.text.style;
18
19
}
20
+
19
21
void main () {
20
22
setUp (() {
21
23
debugResetSemanticsIdCounter ();
@@ -2968,6 +2970,203 @@ void main() {
2968
2970
});
2969
2971
});
2970
2972
2973
+ testWidgets ('AppBar.leading size with custom IconButton' , (WidgetTester tester) async {
2974
+ final Key leadingKey = UniqueKey ();
2975
+ final Key titleKey = UniqueKey ();
2976
+ const double titleSpacing = 16.0 ;
2977
+ final ThemeData theme = ThemeData ();
2978
+
2979
+ await tester.pumpWidget (MaterialApp (
2980
+ home: Scaffold (
2981
+ appBar: AppBar (
2982
+ leading: IconButton (
2983
+ key: leadingKey,
2984
+ onPressed: () {},
2985
+ icon: const Icon (Icons .menu),
2986
+ ),
2987
+ centerTitle: false ,
2988
+ title: Text (
2989
+ 'Title' ,
2990
+ key: titleKey,
2991
+ ),
2992
+ ),
2993
+ ),
2994
+ ));
2995
+
2996
+ final Finder buttonFinder = find.byType (IconButton );
2997
+ expect (tester.getSize (buttonFinder), const Size (48.0 , 48.0 ));
2998
+
2999
+ final TestGesture gesture = await tester.createGesture (
3000
+ kind: PointerDeviceKind .mouse,
3001
+ );
3002
+ await gesture.addPointer ();
3003
+ await gesture.moveTo (tester.getCenter (buttonFinder));
3004
+ await tester.pumpAndSettle ();
3005
+ expect (
3006
+ buttonFinder,
3007
+ paints
3008
+ ..rect (
3009
+ rect: const Rect .fromLTRB (0.0 , 0.0 , 40.0 , 40.0 ),
3010
+ color: theme.colorScheme.onSurface.withOpacity (0.08 ),
3011
+ ),
3012
+ );
3013
+
3014
+ // Get the offset of the Center widget that wraps the IconButton.
3015
+ final Offset backButtonOffset = tester.getTopRight (find.ancestor (
3016
+ of: buttonFinder,
3017
+ matching: find.byType (Center ),
3018
+ ));
3019
+ final Offset titleOffset = tester.getTopLeft (find.byKey (titleKey));
3020
+ expect (titleOffset.dx, backButtonOffset.dx + titleSpacing);
3021
+ });
3022
+
3023
+ testWidgets ('AppBar.leading size with custom BackButton' , (WidgetTester tester) async {
3024
+ final Key leadingKey = UniqueKey ();
3025
+ final Key titleKey = UniqueKey ();
3026
+ const double titleSpacing = 16.0 ;
3027
+ final ThemeData theme = ThemeData ();
3028
+
3029
+ await tester.pumpWidget (MaterialApp (
3030
+ home: Scaffold (
3031
+ appBar: AppBar (
3032
+ leading: BackButton (
3033
+ key: leadingKey,
3034
+ onPressed: () {},
3035
+ ),
3036
+ centerTitle: false ,
3037
+ title: Text (
3038
+ 'Title' ,
3039
+ key: titleKey,
3040
+ ),
3041
+ ),
3042
+ ),
3043
+ ));
3044
+
3045
+ final Finder buttonFinder = find.byType (BackButton );
3046
+ expect (tester.getSize (buttonFinder), const Size (48.0 , 48.0 ));
3047
+
3048
+ final TestGesture gesture = await tester.createGesture (
3049
+ kind: PointerDeviceKind .mouse,
3050
+ );
3051
+ await gesture.addPointer ();
3052
+ await gesture.moveTo (tester.getCenter (buttonFinder));
3053
+ await tester.pumpAndSettle ();
3054
+ expect (
3055
+ buttonFinder,
3056
+ paints
3057
+ ..rect (
3058
+ rect: const Rect .fromLTRB (0.0 , 0.0 , 40.0 , 40.0 ),
3059
+ color: theme.colorScheme.onSurface.withOpacity (0.08 ),
3060
+ ),
3061
+ );
3062
+
3063
+ // Get the offset of the Center widget that wraps the IconButton.
3064
+ final Offset backButtonOffset = tester.getTopRight (find.ancestor (
3065
+ of: buttonFinder,
3066
+ matching: find.byType (Center ),
3067
+ ));
3068
+ final Offset titleOffset = tester.getTopLeft (find.byKey (titleKey));
3069
+ expect (titleOffset.dx, backButtonOffset.dx + titleSpacing);
3070
+ });
3071
+
3072
+ testWidgets ('AppBar.leading size with custom CloseButton' , (WidgetTester tester) async {
3073
+ final Key leadingKey = UniqueKey ();
3074
+ final Key titleKey = UniqueKey ();
3075
+ const double titleSpacing = 16.0 ;
3076
+ final ThemeData theme = ThemeData ();
3077
+
3078
+ await tester.pumpWidget (MaterialApp (
3079
+ home: Scaffold (
3080
+ appBar: AppBar (
3081
+ leading: CloseButton (
3082
+ key: leadingKey,
3083
+ onPressed: () {},
3084
+ ),
3085
+ centerTitle: false ,
3086
+ title: Text (
3087
+ 'Title' ,
3088
+ key: titleKey,
3089
+ ),
3090
+ ),
3091
+ ),
3092
+ ));
3093
+
3094
+ final Finder buttonFinder = find.byType (CloseButton );
3095
+ expect (tester.getSize (buttonFinder), const Size (48.0 , 48.0 ));
3096
+
3097
+ final TestGesture gesture = await tester.createGesture (
3098
+ kind: PointerDeviceKind .mouse,
3099
+ );
3100
+ await gesture.addPointer ();
3101
+ await gesture.moveTo (tester.getCenter (buttonFinder));
3102
+ await tester.pumpAndSettle ();
3103
+ expect (
3104
+ buttonFinder,
3105
+ paints
3106
+ ..rect (
3107
+ rect: const Rect .fromLTRB (0.0 , 0.0 , 40.0 , 40.0 ),
3108
+ color: theme.colorScheme.onSurface.withOpacity (0.08 ),
3109
+ ),
3110
+ );
3111
+
3112
+ // Get the offset of the Center widget that wraps the IconButton.
3113
+ final Offset backButtonOffset = tester.getTopRight (find.ancestor (
3114
+ of: buttonFinder,
3115
+ matching: find.byType (Center ),
3116
+ ));
3117
+ final Offset titleOffset = tester.getTopLeft (find.byKey (titleKey));
3118
+ expect (titleOffset.dx, backButtonOffset.dx + titleSpacing);
3119
+ });
3120
+
3121
+ testWidgets ('AppBar.leading size with custom DrawerButton' , (WidgetTester tester) async {
3122
+ final Key leadingKey = UniqueKey ();
3123
+ final Key titleKey = UniqueKey ();
3124
+ const double titleSpacing = 16.0 ;
3125
+ final ThemeData theme = ThemeData ();
3126
+
3127
+ await tester.pumpWidget (MaterialApp (
3128
+ home: Scaffold (
3129
+ appBar: AppBar (
3130
+ leading: DrawerButton (
3131
+ key: leadingKey,
3132
+ onPressed: () {},
3133
+ ),
3134
+ centerTitle: false ,
3135
+ title: Text (
3136
+ 'Title' ,
3137
+ key: titleKey,
3138
+ ),
3139
+ ),
3140
+ ),
3141
+ ));
3142
+
3143
+ final Finder buttonFinder = find.byType (DrawerButton );
3144
+ expect (tester.getSize (buttonFinder), const Size (48.0 , 48.0 ));
3145
+
3146
+ final TestGesture gesture = await tester.createGesture (
3147
+ kind: PointerDeviceKind .mouse,
3148
+ );
3149
+ await gesture.addPointer ();
3150
+ await gesture.moveTo (tester.getCenter (buttonFinder));
3151
+ await tester.pumpAndSettle ();
3152
+ expect (
3153
+ buttonFinder,
3154
+ paints
3155
+ ..rect (
3156
+ rect: const Rect .fromLTRB (0.0 , 0.0 , 40.0 , 40.0 ),
3157
+ color: theme.colorScheme.onSurface.withOpacity (0.08 ),
3158
+ ),
3159
+ );
3160
+
3161
+ // Get the offset of the Center widget that wraps the IconButton.
3162
+ final Offset backButtonOffset = tester.getTopRight (find.ancestor (
3163
+ of: buttonFinder,
3164
+ matching: find.byType (Center ),
3165
+ ));
3166
+ final Offset titleOffset = tester.getTopLeft (find.byKey (titleKey));
3167
+ expect (titleOffset.dx, backButtonOffset.dx + titleSpacing);
3168
+ });
3169
+
2971
3170
group ('Material 2' , () {
2972
3171
testWidgets ('Material2 - AppBar draws a light system bar for a dark background' , (WidgetTester tester) async {
2973
3172
final ThemeData darkTheme = ThemeData .dark (useMaterial3: false );
0 commit comments