-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix old Standard SearchBar and modify anchor with bar & controller
- Loading branch information
1 parent
100f0c1
commit a237fb2
Showing
5 changed files
with
146 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,97 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:standard_searchbar/new/standard_icons.dart'; | ||
import 'package:standard_searchbar/new/standard_search_anchor.dart'; | ||
|
||
class StandardSearchBar extends StatelessWidget { | ||
const StandardSearchBar({super.key}); | ||
import 'package:standard_searchbar/new/standard_search_controller.dart'; | ||
|
||
class StandardSearchBar extends StatefulWidget { | ||
const StandardSearchBar({ | ||
super.key, | ||
this.width, | ||
this.height = 56, | ||
this.constraints = const BoxConstraints(maxWidth: 720), | ||
this.padding = EdgeInsets.zero, | ||
this.borderRadius = 28, | ||
this.bgColor = Colors.white, | ||
this.leading = const StandardIcons( | ||
icons: [ | ||
Icon(Icons.search, size: 24, color: Colors.grey), | ||
], | ||
), | ||
this.trailing, | ||
}); | ||
|
||
final double? width; | ||
final double height; | ||
final BoxConstraints constraints; | ||
final EdgeInsetsGeometry padding; | ||
final double borderRadius; | ||
final Color bgColor; | ||
|
||
final StandardIcons leading; | ||
final StandardIcons? trailing; | ||
|
||
static StandardSearchAnchorState? of(BuildContext context) { | ||
return context.findAncestorStateOfType<StandardSearchAnchorState>(); | ||
} | ||
|
||
@override | ||
State<StandardSearchBar> createState() => StandardSearchBarState(); | ||
} | ||
|
||
class StandardSearchBarState extends State<StandardSearchBar> { | ||
StandardSearchController? controller; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
controller = StandardSearchBar.of(context)?.controller; | ||
controller?.searchBar = this; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
width: 360, | ||
height: 56, | ||
color: Colors.yellow, | ||
padding: const EdgeInsets.symmetric(horizontal: 16), | ||
width: widget.width, | ||
height: widget.height, | ||
constraints: widget.constraints, | ||
padding: widget.padding, | ||
decoration: BoxDecoration( | ||
borderRadius: getBorderRadius(), | ||
color: widget.bgColor, | ||
), | ||
child: Row( | ||
children: [ | ||
widget.leading, | ||
Expanded( | ||
child: TextField( | ||
controller: controller, | ||
decoration: const InputDecoration( | ||
border: InputBorder.none, | ||
hintText: 'Search', | ||
hintStyle: TextStyle( | ||
color: Colors.grey, | ||
), | ||
), | ||
), | ||
), | ||
if (widget.trailing != null) widget.trailing!, | ||
], | ||
), | ||
); | ||
} | ||
|
||
BorderRadiusGeometry getBorderRadius() { | ||
assert(controller != null); | ||
if (controller!.isOpen) { | ||
return BorderRadius.only( | ||
topLeft: Radius.circular(widget.borderRadius), | ||
topRight: Radius.circular(widget.borderRadius), | ||
); | ||
} else { | ||
return BorderRadius.all( | ||
Radius.circular(widget.borderRadius), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters