我滚动的名单,并在中间,如果我点击了搜索栏,然后名单将自动滚动到索引'0'
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
appBarTheme: const AppBarTheme(
color: Color.fromARGB(255, 218, 255, 144),
),
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
primary: true,
floating: true,
backgroundColor: const Color.fromARGB(255, 218, 255, 144),
snap: true,
pinned: false,
bottom: PreferredSize(
preferredSize: const Size.fromHeight(48),
child: Container(
color: const Color.fromARGB(255, 218, 255, 144),
child: Padding(
padding: const EdgeInsets.only(
left: 15, bottom: 14, right: 15, top: 15),
child: Container(
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: TextFormField(
cursorColor: Colors.black,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(10)),
fillColor:
const Color.fromARGB(30, 50, 50, 122),
contentPadding: const EdgeInsets.all(3),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none),
hintText: 'Search',
hintStyle: const TextStyle(
color: Color.fromARGB(
153,
60,
60,
67,
),
fontSize: 17,
fontWeight: FontWeight.w400),
filled: true,
prefixIcon: const Icon(
Icons.search,
color: Color.fromARGB(
153,
60,
60,
67,
),
),
suffixIcon: MaterialButton(
minWidth: 10,
splashColor: Colors.grey,
onPressed: () {},
child: const Icon(
Icons.clear,
color: Color.fromARGB(
153,
60,
60,
67,
),
))),
),
),
),
),
),
),
),
];
},
body: const MyScreen(),
),
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
toolbarHeight: 48,
automaticallyImplyLeading: true,
elevation: 0,
title: const Text("My Title"),
centerTitle: true,
actions: [
IconButton(
icon: const Icon(Icons.favorite_border_rounded,
color: Color.fromARGB(223, 0, 0, 0)),
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.shopping_cart_rounded,
color: Color.fromARGB(223, 0, 0, 0)),
onPressed: () {},
),
],
),
),
],
),
);
}
}
class MyScreen extends StatelessWidget {
const MyScreen({super.key});
@override
Widget build(BuildContext context) {
return ListView.separated(
itemCount: 1000,
itemBuilder: (context, index) => Text(index.toString()),
separatorBuilder: (context, index) => const Divider());
}
}
当我点击搜索栏时,我试图停止自动滚动,所以请帮助我停止自动滚动开始,并删除应用程序栏和列表后的间隙,请美化代码,抱歉我的英语很差.