How Can I keep the text field fixed? Currently when I am scrolling to top its also going with the list. I need to keep it fixed.
Widget build(BuildContext context) {
final localStorage = GetStorage();
return Scaffold(
appBar: HomePageAppBar(),
drawer: HomePageNavigationDrawer(localStorage),
body: SingleChildScrollView(
child: Column(
children: [
TextField(
onChanged: (value) => _runFilter(value),
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 10.0,horizontal: 10.0),
hintText: "Search",
suffixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: const BorderSide(),
),
),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _allUsers.length,
itemBuilder: (context, index) => Card(
elevation: 1,
margin: const EdgeInsets.symmetric(vertical: 2),
child: ListTile(
title: Text(_allUsers[index]['name']),
subtitle: Text('${_allUsers[index]["generic"]}'),
),
),
),
],
),
),
bottomNavigationBar: const HomePageBottomNavigation(),
);
}
2
Answers
You could try putting your TextField outside your Scroll widget, removing the unnecesary SingleChildScrollView, and replacing the scroll physics in your ListView:
you can use CustomScrollView with a SliverAppBar for the search bar
like this:-