1、导航搜索栏:固定
2、tab切换:固定
3、列表分页:滚动
import 'package:demo/common/index.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'index.dart';
class CardPage extends GetView<CardController> {
const CardPage({super.key});
// 头部
Widget _buildHeader() {
return <Widget>[
].toRow().card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(34.w),
),
).tight(width: 690.w,height: 80.w).marginOnly(top: 30.w,bottom: 30.w);
}
// 列表
Widget _buildList() {
return SmartRefresher(
controller: controller.refreshController,
enablePullUp: true, // 启用上拉加载
onRefresh: controller.onRefresh, // 下拉刷新回调
onLoading: controller.onLoading, // 上拉加载回调
footer: const SmartRefresherFooterWidget(), // 底部加载更多组件
child: ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return Text('列表项 $index');
},
),
);
}
// 主视图
Widget _buildView() {
return <Widget>[
_buildHeader(),
Expanded(child: _buildList()),
].toColumn();
}
@override
Widget build(BuildContext context) {
return GetBuilder<CardController>(
init: CardController(),
id: "card",
builder: (_) {
return Scaffold(
backgroundColor: const Color(0xffF5F5F5),
appBar: TDNavBar(
padding: EdgeInsets.only(left: 0,right: 0), // 重写左右内边距
centerTitle:false, // 不显示标题
height: 45, // 高度
titleWidget: <Widget>[
TDImage(
assetUrl: 'assets/img/search.png',
width: 32.w,
height: 32.w,
),
SizedBox(width: 20.w,),
<Widget>[
].toRow().tight(height: 28.w).decorated(
border: Border(
left: BorderSide(color: const Color(0xffe9e9e9),width: 1.w),
),
),
SizedBox(width: 20.w,),
TextWidget.body('搜索心仪的商品',color: const Color(0xff999999),size: 28.sp,),
].toRow().paddingHorizontal(30.w).card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(34.w),
),
).tight(height: 68.w),
backgroundColor: const Color(0xffE93323), // 背景
screenAdaptation: true, // 默认true,适配手机状态栏高度
useDefaultBack: false, // 显示左侧返回按键
),
body: SafeArea(
child: _buildView()
),
);
},
);
}
}