我正在开发一个像直播电视这样的应用程序,它基本上是一个基于视频的推荐平台
我注意到,当我滚动应用程序的“主页”时,有状态小部件被一次又一次调用(因为我正在使用 Future 构建器),因此它会导致大量数据消耗,这是一个严重的问题我希望它不要发生。
我按照本文使用了记忆化的概念https://medium.com/saugo360/flutter-my-futurebuilder-keeps-firing-6e774830bc2。代码不会抛出任何错误。但是使用它后我的主页无法加载。我不明白为什么会发生这种情况?
这是我未来的构建器代码:
@override
Widget build(BuildContext context) {
print("Build function called......................");
body: SafeArea(
child: SingleChildScrollView(
controller: _scrollController,
child: FutureBuilder(
future: widgetLoadingFunctions(_selectedIndex),
builder:
(BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return widgetOptions(_selectedIndex);
} else
return //Asset.image('assets/loading.gif');
Image.asset('assets/loading.gif');
})),
),
drawer: Drawer(),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.black,
showUnselectedLabels: true,
type: BottomNavigationBarType.shifting,
currentIndex: _selectedIndex,
fixedColor: Colors.amber,
onTap: (int index) {
setState(() {
_selectedIndex = index;
});
},
items: <BottomNavigationBarItem>[
// Icon(
// FontAwesome.facebook_square,
// color: Colors.amber,
// ), …Run Code Online (Sandbox Code Playgroud) 您好,我正在使用 FadeInImage.assetNetwork 来显示我的图像。但无论我尝试什么,我都没有得到圆角矩形边框。我尝试了 Clipperrect,但图像没有被剪切,但卡片被剪切。我什至尝试将 FadeInImage.assetNetwork 包装在 CLperect 中,并尝试包装在容器中并给予装饰,例如但这似乎没有给出预期的结果。
简而言之,图像没有被剪切,但卡片被剪切。我们如何解决这个问题?
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
Container(
height: MediaQuery.of(context).size.height * 0.27,
color: Colors.black,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: __moviesMovieId.length,
itemBuilder: (BuildContext context, int index) => Card(
margin: const EdgeInsets.fromLTRB(0, 0, 15, 0),
child: FadeInImage.assetNetwork(
width: MediaQuery.of(context).size.width * 0.3,
image:
'https://img.youtube.com/vi/${__moviesMovieId[index].substring(8)}/0.jpg',
placeholder: cupertinoActivityIndicator,
fit: BoxFit.fill,
),
),
),
),
Run Code Online (Sandbox Code Playgroud)