gpt4 book ai didi

flutter - 可以在 TabBarView 内部使用 SliverList,反之亦然?

转载 作者:行者123 更新时间:2023-12-05 01:30:26 26 4
gpt4 key购买 nike

我正在尝试在 TabBarView 中使用 SliverList 但我不断收到这些错误:

  1. 断言失败:第 5966 行第 12 行:“child == _child”:不正确。
  2. RenderRepaintBoundary 需要一个 RenderBox 类型的子对象,但收到了一个RenderSliv​​erFillRemainingWithScrollable 类型的子项。这是代码。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MoboApp(),
);
}
}

class MoboApp extends StatefulWidget {
@override
_MoboAppState createState() => _MoboAppState();
}

class _MoboAppState extends State<MoboApp> with SingleTickerProviderStateMixin {

@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
leading: Icon(
Icons.list,
color: Color(0xFFFBF3F3),
),
actions: [
Icon(
Icons.more_vert,
color: Color(0xFFFBF3F3),
)
],
title: Text(
'mobo app',
style: TextStyle(
color: Color(0xFFFBF3F3),
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
pinned: true,
floating: false,
expandedHeight: 100.0,
bottom: TabBar(
unselectedLabelColor: Color(0xFFE0A1A1),
tabs: <Widget>[
Tab(
text: 'Home',
),
Tab(
text: 'Feed',
),
Tab(
text: 'Profile',
),
Tab(
text: 'Setting',
)
],
),
backgroundColor: Color(0xFFBB1A1A),
),
TabBarView(
children: [
// FIRST TabBarView
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network(
'https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),

// SECOND TabBarView
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network(
'https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),

//THIRD TabBarView
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network(
'https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),

//FOURTH TabBarView
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network(
'https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),
],
)
],
),
),
);
}
}

最佳答案

所以...我尽量不对您的代码进行过多更改 :-)。此代码适用于 Android:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MoboApp(),
);
}
}

class MoboApp extends StatefulWidget {
@override
_MoboAppState createState() => _MoboAppState();
}

class _MoboAppState extends State<MoboApp> with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Builder(builder: (BuildContext context) {
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
leading: Icon(
Icons.list,
color: Color(0xFFFBF3F3),
),
actions: [
Icon(
Icons.more_vert,
color: Color(0xFFFBF3F3),
)
],
title: Text(
'mobo app',
style: TextStyle(
color: Color(0xFFFBF3F3),
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
pinned: true,
floating: false,
expandedHeight: 100.0,
bottom: TabBar(
unselectedLabelColor: Color(0xFFE0A1A1),
tabs: <Widget>[
Tab(
text: 'Home',
),
Tab(
text: 'Feed',
),
Tab(
text: 'Profile',
),
Tab(
text: 'Setting',
)
],
),
backgroundColor: Color(0xFFBB1A1A),
),
];
},
body: TabBarView(
children: [
// FIRST TabBarView
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network('https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),
],
),

// SECOND TabBarView
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network('https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),
],
),

//THIRD TabBarView
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network('https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),
],
),

//FOURTH TabBarView
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Image.network('https://cdn.britannica.com/24/58624-050-73A7BF0B/valley-Atlas-Mountains-Morocco.jpg',
fit: BoxFit.cover,
),
),
),
],
),
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.white,
width: double.infinity,
child: Text('text'),
),
),
],
),
],
),
),
],
)
],
),
);
}),
);
}
}

关于flutter - 可以在 TabBarView 内部使用 SliverList,反之亦然?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67001015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com