Skip to content

Instantly share code, notes, and snippets.

Avatar

Nishant Desai NishantDesai1306

View GitHub Profile
@NishantDesai1306
NishantDesai1306 / search_bar.dart
Created Jun 29, 2019
wiring up the callback functions to widgets in search bar
View search_bar.dart
// register that SearchBar will need these callbacks
SearchBar({
Key key,
@required this.onCancelSearch,
@required this.onSearchQueryChanged,
}) : super(key: key);
final VoidCallback onCancelSearch;
final Function(String) onSearchQueryChanged;
@NishantDesai1306
NishantDesai1306 / default_app_bar.dart
Created Jun 29, 2019
adding callback functions so that default app bar can communicate with search bar
View default_app_bar.dart
// add this method to default app bar class
// this will get executed when user pressed back arrow on search bar
cancelSearch() {
// remove search bar from stack
setState(() {
isInSearchMode = false;
});
// change search value to ''
onSearchQueryChange('');
View search_bar.dart
class SearchBar extends StatefulWidget implements PreferredSizeWidget {
@override
Size get preferredSize => Size.fromHeight(56.0);
@override
_SearchBarState createState() => _SearchBarState();
}
class _SearchBarState extends State<SearchBar> with SingleTickerProviderStateMixin {
String searchQuery = '';
@NishantDesai1306
NishantDesai1306 / default_app_bar.dart
Created Jun 29, 2019
registering animation listener to our animation controller
View default_app_bar.dart
bool isInSearchMode = false;
// inside initState register our status listener
_controller.addStatusListener(animationStatusListener);
// add this method to our DefaultAppBar widget
animationStatusListener(AnimationStatus animationStatus) {
if (animationStatus == AnimationStatus.completed) {
setState(() {
isInSearchMode = true;
@NishantDesai1306
NishantDesai1306 / default_app_bar.dart
Created Jun 29, 2019
portion of default_app_bar.dart
View default_app_bar.dart
// add SingleTickerProviderStateMixin to our State widget
class _DefaultAppBarState extends State<DefaultAppBar> with SingleTickerProviderStateMixin {
}
// intialize animation and controller
AnimationController _controller;
Animation _animation;
@override
initState() {
@NishantDesai1306
NishantDesai1306 / MyPainter.dart
Created Jun 29, 2019
code for custom painter
View MyPainter.dart
class MyPainter extends CustomPainter {
final Offset center;
final double radius, containerHeight;
final BuildContext context;
Color color;
double statusBarHeight, screenWidth;
MyPainter({this.context, this.containerHeight, this.center, this.radius}) {
ThemeData theme = Theme.of(context);
@NishantDesai1306
NishantDesai1306 / tap_details.dart
Created Jun 29, 2019
Get the location where user tapped on the search button
View tap_details.dart
double rippleStartX, rippleStartY;
void onSearchTapUp(TapUpDetails details) {
setState(() {
rippleStartX = details.globalPosition.dx;
rippleStartY = details.globalPosition.dy;
});
print("pointer location $rippleStartX, $rippleStartY");
}
View default_app_bar.dart
class DefaultAppBar extends StatefulWidget implements PreferredSizeWidget {
@override
Size get preferredSize => Size.fromHeight(56.0);
@override
_DefaultAppBarState createState() => _DefaultAppBarState();
}
class _DefaultAppBarState extends State<DefaultAppBar> {
@override
View homepage.dart
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
You can’t perform that action at this time.