Flutter 商城应用 - 底部导航栏跳转购物车页面
import 'package:ecommerce_muse/pages/CartPage.dart'; import 'package:ecommerce_muse/pages/ProductDetailPage.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import '../models/product.dart'; import '../services/api_service.dart';
class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); }
class _HomePageState extends State
void _onLoading() async {
_page++;
List
@override void initState() { super.initState(); _loadProducts();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 300),
);
_animation = Tween<double>(begin: 1, end: 0.95).animate(
CurvedAnimation(
parent: _animationController!,
curve: Curves.easeInOut,
),
);
}
Future
@override void dispose() { _animationController!.dispose(); super.dispose(); }
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('商城主页')),
body: SmartRefresher(
enablePullDown: false,
enablePullUp: true,
controller: _refreshController,
onLoading: _onLoading,
child: GridView.builder(
itemCount: _products.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.75,
),
itemBuilder: (BuildContext context, int index) {
final product = _products[index];
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ProductDetailPage(productId: product.id),
),
);
},
child: ScaleTransition(
scale: _animation!,
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children:
原文地址: https://www.cveoy.top/t/topic/oiiR 著作权归作者所有。请勿转载和采集!