【发布时间】:2022-01-13 18:06:01
【问题描述】:
包装在扩展小部件中的 ProductModel 类在它自己的容器中滚动,我怎样才能让它滚动整个页面。 ..................................................... ..................................................... ..................................................... ................................................
主页类
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
int _current;
return Scaffold(
appBar: AppBar(
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.notifications_active,
color: Mythemes.darkbluishcolor,
),
)
],
),
drawer: MyDrawer(),
body: SafeArea(
child: SingleChildScrollView(
child: Container(
color: Mythemes.creamcolor,
height: MediaQuery.of(context).size.height,
child: (CatalogModel.items != null && CatalogModel.items.isNotEmpty)
? Padding(
padding: const EdgeInsets.all(14.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
PageHeader(),
Expanded(
child: SpecialPrice(),
flex: 2,
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 12, 8, 2),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Popular Brands",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Mythemes.darkbluishcolor,
),
),
Text(
"See all",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black54,
),
),
],
),
),
Expanded(
child: HoriScrollList(),
flex: 2,
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 12, 8, 2),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Best Sellers",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Mythemes.darkbluishcolor,
),
),
Text(
"See all",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.black54,
),
),
],
),
),
Expanded(
child: BestSellers(),
flex: 3,
),
Expanded(child: ProductModel(),flex: 3,),
],
),
)
: Center(child: CircularProgressIndicator()),
),
),
),
);
}
}
ProductModel 类
class ProductModel extends StatelessWidget {
const ProductModel({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: CatalogModel.items.length,
itemBuilder: (context, index) {
final catalogitem = CatalogModel.items[index];
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ProductCart(item: CatalogModel.items[index])));
},
child: ProductView(item: catalogitem));
});
}
}
【问题讨论】: