Skip to content

Commit

Permalink
Fix issue #176
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshj01 committed Sep 21, 2024
1 parent af74a8d commit db99309
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 51 deletions.
104 changes: 53 additions & 51 deletions lib/src/input_decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class SearchInputDecoration extends InputDecoration {
super.errorStyle,
});

@override
SearchInputDecoration copyWith({
Key? key,
Color? cursorColor,
Expand Down Expand Up @@ -182,57 +183,58 @@ class SearchInputDecoration extends InputDecoration {
String? suffixText,
}) {
return SearchInputDecoration(
key: key,
cursorColor: cursorColor ?? this.cursorColor,
cursorErrorColor: cursorErrorColor,
cursorHeight: cursorHeight,
cursorWidth: cursorWidth,
cursorOpacityAnimates: cursorOpacityAnimates,
cursorRadius: cursorRadius,
keyboardAppearance: keyboardAppearance,
alignLabelWithHint: alignLabelWithHint,
border: border,
constraints: constraints,
contentPadding: contentPadding,
counter: counter,
counterStyle: counterStyle,
counterText: counterText,
disabledBorder: disabledBorder,
enabledBorder: enabledBorder,
errorBorder: errorBorder,
errorMaxLines: errorMaxLines,
errorStyle: errorStyle,
fillColor: fillColor,
filled: filled,
floatingLabelAlignment: floatingLabelAlignment,
floatingLabelBehavior: floatingLabelBehavior,
focusColor: focusColor,
focusedBorder: focusedBorder,
focusedErrorBorder: focusedErrorBorder,
helperMaxLines: helperMaxLines,
helperStyle: helperStyle,
helperText: helperText,
hintStyle: hintStyle,
hintText: hintText,
hoverColor: hoverColor,
icon: icon,
iconColor: iconColor,
isCollapsed: isCollapsed,
isDense: isDense,
label: label,
labelStyle: labelStyle,
labelText: labelText,
prefix: prefix,
prefixIcon: prefixIcon,
prefixIconColor: prefixIconColor,
prefixStyle: prefixStyle,
prefixText: prefixText,
semanticCounterText: semanticCounterText,
suffix: suffix,
suffixIcon: suffixIcon,
suffixIconColor: suffixIconColor,
suffixStyle: suffixStyle,
suffixText: suffixText,
cursorErrorColor: cursorErrorColor ?? this.cursorErrorColor,
cursorHeight: cursorHeight ?? this.cursorHeight,
cursorWidth: cursorWidth ?? this.cursorWidth,
cursorOpacityAnimates:
cursorOpacityAnimates ?? this.cursorOpacityAnimates,
cursorRadius: cursorRadius ?? this.cursorRadius,
keyboardAppearance: keyboardAppearance ?? this.keyboardAppearance,
alignLabelWithHint: alignLabelWithHint ?? this.alignLabelWithHint,
border: border ?? this.border,
constraints: constraints ?? this.constraints,
contentPadding: contentPadding ?? this.contentPadding,
counter: counter ?? this.counter,
counterStyle: counterStyle ?? this.counterStyle,
counterText: counterText ?? this.counterText,
disabledBorder: disabledBorder ?? this.disabledBorder,
enabledBorder: enabledBorder ?? this.enabledBorder,
errorBorder: errorBorder ?? this.errorBorder,
errorMaxLines: errorMaxLines ?? this.errorMaxLines,
errorStyle: errorStyle ?? this.errorStyle,
fillColor: fillColor ?? this.fillColor,
filled: filled ?? this.filled,
floatingLabelAlignment:
floatingLabelAlignment ?? this.floatingLabelAlignment,
floatingLabelBehavior:
floatingLabelBehavior ?? this.floatingLabelBehavior,
focusColor: focusColor ?? this.focusColor,
focusedBorder: focusedBorder ?? this.focusedBorder,
focusedErrorBorder: focusedErrorBorder ?? this.focusedErrorBorder,
helperMaxLines: helperMaxLines ?? this.helperMaxLines,
helperStyle: helperStyle ?? this.helperStyle,
helperText: helperText ?? this.helperText,
hintStyle: hintStyle ?? this.hintStyle,
hintText: hintText ?? this.hintText,
hoverColor: hoverColor ?? this.hoverColor,
icon: icon ?? this.icon,
iconColor: iconColor ?? this.iconColor,
isCollapsed: isCollapsed ?? this.isCollapsed,
isDense: isDense ?? this.isDense,
label: label ?? this.label,
labelStyle: labelStyle ?? this.labelStyle,
labelText: labelText ?? this.labelText,
prefix: prefix ?? this.prefix,
prefixIcon: prefixIcon ?? this.prefixIcon,
prefixIconColor: prefixIconColor ?? this.prefixIconColor,
prefixStyle: prefixStyle ?? this.prefixStyle,
prefixText: prefixText ?? this.prefixText,
semanticCounterText: semanticCounterText ?? this.semanticCounterText,
suffix: suffix ?? this.suffix,
suffixIcon: suffixIcon ?? this.suffixIcon,
suffixIconColor: suffixIconColor ?? this.suffixIconColor,
suffixStyle: suffixStyle ?? this.suffixStyle,
suffixText: suffixText ?? this.suffixText,
);
}
}
116 changes: 116 additions & 0 deletions test/searchfield_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1561,4 +1561,120 @@ void main() {
// await widgetTester.pumpAndSettle(Duration(seconds: 1));
// expect(scrollOffset, 100.0);
// });
testWidgets('SearchInputdecoration values can be set', (widgetTester) async {
final suggestions = List.generate(500, (index) => index.toString())
.map((e) => SearchFieldListItem<String>(e))
.toList();

double scrollOffset = 0.0;
await widgetTester.pumpWidget(_boilerplate(
child: SearchField<String>(
key: const Key('searchfield'),
suggestions: suggestions,
searchInputDecoration: SearchInputDecoration(
hintText: 'Search',
labelText: 'Search',
prefixIcon: Icon(Icons.search),
suffixIcon: Icon(Icons.close),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
contentPadding: EdgeInsets.all(10),
counterText: 'Counter',
counterStyle: TextStyle(color: Colors.red),
counter: Container(),
errorMaxLines: 2,
errorStyle: TextStyle(color: Colors.red),
fillColor: Colors.red,
filled: true,
focusColor: Colors.red,
hoverColor: Colors.red,
labelStyle: TextStyle(color: Colors.red),
alignLabelWithHint: true,
constraints: BoxConstraints(
minHeight: 100,
maxHeight: 100,
),
floatingLabelBehavior: FloatingLabelBehavior.never,
isCollapsed: true,
isDense: true,
prefix: Container(),
suffix: Container(),
),
suggestionState: Suggestion.expand,
onScroll: (offset, maxOffset) {
print(offset);
scrollOffset = offset;
},
)));

// Find the SearchField widget
final searchFieldFinder = find.byKey(const Key('searchfield'));
expect(searchFieldFinder, findsOneWidget);

// Find the TextField within SearchField
final textFieldFinder = find.descendant(
of: searchFieldFinder,
matching: find.byType(TextField),
);
expect(textFieldFinder, findsOneWidget);

// Get the InputDecoration from the TextField
final TextField textField = widgetTester.widget<TextField>(textFieldFinder);
final InputDecoration? decoration = textField.decoration;

// Verify InputDecoration properties
expect(decoration, isNotNull);
expect(decoration!.hintText, 'Search');
expect(decoration.labelText, 'Search');
expect(decoration.prefixIcon, isA<Icon>());
expect(decoration.suffixIcon, isA<Icon>());
expect(decoration.border, isA<OutlineInputBorder>());
expect(decoration.focusedBorder, isA<OutlineInputBorder>());
expect(decoration.enabledBorder, isA<OutlineInputBorder>());
expect(decoration.errorBorder, isA<OutlineInputBorder>());
expect(decoration.focusedErrorBorder, isA<OutlineInputBorder>());
expect(decoration.disabledBorder, isA<OutlineInputBorder>());
expect(decoration.contentPadding, EdgeInsets.all(10));
expect(decoration.counterText, 'Counter');
expect(decoration.counterStyle, isA<TextStyle>());
expect(decoration.counterStyle!.color, Colors.red);
expect(decoration.counter, isA<Container>());
expect(decoration.errorMaxLines, 2);
expect(decoration.errorStyle, isA<TextStyle>());
expect(decoration.errorStyle!.color, Colors.red);
expect(decoration.fillColor, Colors.red);
expect(decoration.filled, true);
expect(decoration.focusColor, Colors.red);
expect(decoration.hoverColor, Colors.red);
expect(decoration.labelStyle, isA<TextStyle>());
expect(decoration.labelStyle!.color, Colors.red);
expect(decoration.alignLabelWithHint, true);
expect(decoration.constraints, isA<BoxConstraints>());
expect(decoration.constraints!.minHeight, 100);
expect(decoration.constraints!.maxHeight, 100);
expect(decoration.floatingLabelBehavior, FloatingLabelBehavior.never);
expect(decoration.isCollapsed, true);
expect(decoration.isDense, true);
expect(decoration.prefix, isA<Container>());
expect(decoration.suffix, isA<Container>());
// You can add more specific tests for border radius if needed
final OutlineInputBorder border = decoration.border as OutlineInputBorder;
expect(border.borderRadius, BorderRadius.circular(10));
});
}

0 comments on commit db99309

Please sign in to comment.