我正在嘗試創建與我的物件相關的 PageView,但是當我加載時,第一個專案沒有顯示。它像螢屏截圖中一樣是空白的。列印功能作業正常,它列印現有專案但我無法查看它。
列印結果 item : itemfirst
Scaffold(
backgroundColor: colordtmainone,
body: NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
floating: true,
elevation: 0,
backgroundColor: colordtmainone,
toolbarHeight: 0,
expandedHeight: 0,
forceElevated: innerBoxIsScrolled,
),
];
},
body: PageView.builder(
onPageChanged: (indexpage){
if (indexpage 1 == _userservicesForDisplay.length) {
page = page 1;
_loadmoreuserservices();
}
},
scrollDirection: Axis.vertical,
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
for(final item in _userservicesForDisplay)print('item: ${item.service}');
return index == 0 ? SizedBox(height:0,width:0) : _listItemUserService(index-1);},
itemCount: _userservicesForDisplay.length 1,
),
),
)

uj5u.com熱心網友回復:
在這里,您正在跳過第一個元素。如果index = 0,則回傳一個 SizedBox(height:0,width:0)。
return index == 0 ? SizedBox(height:0,width:0) : _listItemUserService(index-1);},
所以你可以
itemBuilder: (_, index) {
return _listItemUserService(index);
},
itemCount: _userservicesForDisplay.length,
uj5u.com熱心網友回復:
you can use this code for your reference hope this will work for you thanks
import 'package:flutter/material.dart';
import 'package:traveling/helpers/AppColors.dart';
import 'package:traveling/screens/Employee/home/Home.dart';
import 'package:traveling/screens/Employee/profile/Profile.dart';
import 'package:traveling/screens/Employee/setting/Setting.dart';
class EmployeeBottomNavBar extends StatefulWidget {
const EmployeeBottomNavBar({Key? key}) : super(key: key);
@override
_EmployeeBottomNavBarState createState() => _EmployeeBottomNavBarState();
}
class _EmployeeBottomNavBarState extends State<EmployeeBottomNavBar> {
int pageIndex = 0;
bool visible = true;
List<Widget> pageList = <Widget>[EmployeeHome(), EmployeeProfile(leadingIcon: false,), Setting()];
@override
Widget build(BuildContext context) {
return Scaffold(
body: pageList[pageIndex],
bottomNavigationBar: BottomNavigationBar(
fixedColor: Colors.redAccent[400],
currentIndex: pageIndex,
onTap: (value) {
setState(() {
pageIndex = value;
});
},
// type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
activeIcon: Container(
height: 40,
width: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xff2161c0),
),
child: Icon(
Icons.home,
color: AppColors.white,
),
),
icon: Icon(
Icons.home,
color: Color(0xff2161c0),
),
label: ""),
BottomNavigationBarItem(
activeIcon: Container(
height: 40,
width: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xff2161c0),
),
child: Icon(
Icons.person,
color: AppColors.white,
),
),
icon: Icon(
Icons.person,
color: AppColors.baseLightBlueColor,
),
label: ""),
BottomNavigationBarItem(
activeIcon: Container(
height: 40,
width: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColors.baseLightBlueColor,
),
child: Icon(
Icons.settings,
color: AppColors.white,
),
),
icon: Icon(
Icons.settings,
color: AppColors.baseLightBlueColor,
),
label: ""),
]
)
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/408830.html
標籤:
