mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
102 lines
3.6 KiB
Dart
102 lines
3.6 KiB
Dart
import 'package:animations/animations.dart';
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:fladder/providers/user_provider.dart';
|
|
import 'package:fladder/routes/build_routes/route_builder.dart';
|
|
import 'package:fladder/routes/build_routes/settings_routes.dart';
|
|
import 'package:fladder/screens/search/search_screen.dart';
|
|
import 'package:fladder/util/string_extensions.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class FloatingSearchBar extends ConsumerStatefulWidget {
|
|
final List<Widget> trailing;
|
|
final String hintText;
|
|
final bool showLoading;
|
|
final bool showUserIcon;
|
|
final bool automaticallyImplyLeading;
|
|
final double height;
|
|
const FloatingSearchBar({
|
|
this.trailing = const [],
|
|
this.showLoading = false,
|
|
this.showUserIcon = true,
|
|
this.height = 50,
|
|
required this.hintText,
|
|
this.automaticallyImplyLeading = true,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _FloatingSearchBarState();
|
|
}
|
|
|
|
class _FloatingSearchBarState extends ConsumerState<FloatingSearchBar> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final user = ref.watch(userProvider);
|
|
return Hero(
|
|
tag: "FloatingSearchBarHome",
|
|
child: SizedBox(
|
|
height: widget.height,
|
|
width: double.infinity,
|
|
child: OpenContainer(
|
|
openBuilder: (context, action) {
|
|
return const SearchScreen();
|
|
},
|
|
openColor: Colors.transparent,
|
|
openElevation: 0,
|
|
closedColor: Colors.transparent,
|
|
closedElevation: 0,
|
|
closedBuilder: (context, openAction) => Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
shadowColor: Colors.transparent,
|
|
elevation: 5,
|
|
margin: EdgeInsets.zero,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(500)),
|
|
child: InkWell(
|
|
onTap: () => openAction(),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
if (context.canPop())
|
|
IconButton(
|
|
onPressed: () => context.pop(),
|
|
icon: const Icon(Icons.arrow_back),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
widget.hintText,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
)),
|
|
IconButton(
|
|
onPressed: () => openAction(),
|
|
icon: const Icon(
|
|
Icons.search_rounded,
|
|
),
|
|
),
|
|
IconButton(
|
|
onPressed: () {
|
|
context.routeGo(SecuritySettingsRoute());
|
|
},
|
|
icon: ClipRRect(
|
|
borderRadius: BorderRadius.circular(200),
|
|
child: CachedNetworkImage(
|
|
imageUrl: user?.avatar ?? "",
|
|
memCacheHeight: 125,
|
|
imageBuilder: (context, imageProvider) => Image(image: imageProvider),
|
|
errorWidget: (context, url, error) => CircleAvatar(
|
|
child: Text(user?.name.getInitials() ?? ""),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|