我使用SliverList隐藏了刷卡器,但是它给了我关于刷卡器控制器的错误(我认为),该消息未保存状态,或者有什么可以帮助我修复它,非常感谢
UI代码
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:medixa_app/Routes/CategoryRoute.dart';
class HomeTab extends StatefulWidget {
@override
_HomeTabState createState() => _HomeTabState();
}
class _HomeTabState extends State<HomeTab> {
var names = [
'INFO',
'ABOUT',
'EVO',
'CONTACT US',
];
var links = [
'https://images.pexels.com/photos/1282308/pexels-photo-1282308.jpeg?auto=compress&cs=tinysrgb&h=650&w=940',
'https://images.pexels.com/photos/40568/medical-appointment-doctor-healthcare-40568.jpeg?auto=compress&cs=tinysrgb&h=650&w=940',
'https://images.pexels.com/photos/935869/pexels-photo-935869.jpeg?auto=compress&cs=tinysrgb&h=650&w=940',
];
var swiperController;
List<StackFit> stackList = [StackFit.expand, StackFit.loose];
@override
void initState() {
super.initState();
swiperController = SwiperControl(
iconPrevious: null,
iconNext: null,
);
}
@override
Widget build(BuildContext context) {
return Material(
child: Container(
child: CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
<Widget>[
Container(
height: 50.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: names.length,
itemBuilder: (context, i) => new MenuItem(names[i], i),
),
),
new Container(
height: 150.0,
child: Swiper(
loop: false,
autoplay: true,
itemBuilder: (context, i) {
return Stack(
alignment: AlignmentDirectional.bottomStart,
fit: StackFit.expand,
children: <Widget>[
Image.network(
links[i],
fit: BoxFit.cover,
),
Container(
alignment: AlignmentDirectional.bottomStart,
child: Container(
constraints:
BoxConstraints(minWidth: double.maxFinite),
padding: EdgeInsets.symmetric(
vertical: 8.0, horizontal: 16.0),
color: Colors.black54,
child: Text(
'Descreption: ${i}',
style: TextStyle(
color: Colors.white,
),
textAlign: TextAlign.justify,
),
),
)
],
);
},
itemCount: links.length,
pagination: new SwiperPagination(),
control: swiperController,
),
),
],
addAutomaticKeepAlives: true,
addRepaintBoundaries: false
),
),
SliverList(
delegate: SliverChildBuilderDelegate((context, i) {
return new Container(
height: 80.0,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: <Widget>[
Icon(
Icons.account_circle,
color: Colors.deepPurple[((i + 1) % 10) * 100],
size: 48.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Center(
child: Text('Title: ${i + 1}'),
),
)
],
),
),
);
}, childCount: 20),
)
],
),
),
);
}
}
class MenuItem extends StatelessWidget {
final String title;
final int id;
MenuItem(this.title, this.id);
@override
Widget build(BuildContext context) {
return Material(
child: Card(
margin: EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 8.0,
),
child: InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new CategoryRoute(title, id)));
},
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(title),
),
),
),
),
);
}
}
错误
I / flutter(2601):BY基础库引起的异常CA ═════════════════════════ I / flutter(2601):调度SwiperController的通知时引发了以下断言: I / flutter(2601):查找停用的窗口小部件的祖先是不安全的。 I / flutter(2601):这时小部件的元素树的状态不再稳定。为了安全地参考 I / flutter(2601):小部件的祖先在其dispose()方法中,通过调用保存对祖先的引用 I / flutter(2601):窗口小部件的didChangeDependencies()方法中的InheritedFromWidgetOfExactType()。 I / flutter(2601):引发异常时,这是堆栈: I /颤振(2601):#0 Element._debugCheckStateIsActiveForAncestorLookup。 (包:flutter / src / widgets / framework.dart:3233:9) I / flutter(2601):#1 Element._debugCheckStateIsActiveForAncestorLookup(包:flutter / src / widgets / framework.dart:3242:6) I / flutter(2601):#2 Element.visitAncestorElements(包:flutter / src / widgets / framework.dart:3329:12) I / flutter(2601):#3 Notification.dispatch(软件包:flutter / src / widgets / notification_listener.dart:59:12) I / flutter(2601):#4 ScrollActivity.dispatchScrollEndNotification(package:flutter / src / widgets / scroll_activity.dart:106:63) I / flutter(2601):#5 ScrollPosition.didEndScroll(package:flutter / src / widgets / scroll_position.dart:639:14) I / flutter(2601):#6 ScrollPosition.beginActivity(包:flutter / src / widgets / scroll_position.dart:608:9) I / flutter(2601):#7 ScrollPositionWithSingleContext.beginActivity(包:flutter / src / widgets / scroll_position_with_single_context.dart:117:11) I / flutter(2601):#8 ScrollPositionWithSingleContext.goIdle(包:flutter / src / widgets / scroll_position_with_single_context.dart:132:5) I / flutter(2601):#9 ScrollPositionWithSingleContext.jumpTo(包:flutter / src / widgets / scroll_position_with_single_context.dart:196:5) I / flutter(2601):#10 ScrollPositionWithSingleContext.animateTo(包:flutter / src / widgets / scroll_position_with_single_context.dart:178:7) I / flutter(2601):#11 PageController.animateToPage(package:flutter / src / widgets / page_view.dart:119:21) I / flutter(2601):#12 _TransformerPageViewState.onChangeNotifier(package:transformer_page_view / transformer_page_view.dart:582:12) I / flutter(2601):#13 ChangeNotifier.notifyListeners(package:flutter / src / foundation / change_notifier.dart:161:21) I / flutter(2601):#14 IndexController.next(package:transformer_page_view / index_controller.dart:70:5) I / flutter(2601):#15 _SwiperTimerMixin._onTimer(软件包:flutter_swiper / src / swiper.dart:370:17) I / Flutter(2601):#16 _Timer._runTimers(dart:isolate / runtime / libtimer_impl.dart:382:19) I / Flutter(2601):#17 _Timer._handleMessage(dart:isolate / runtime / libtimer_impl.dart:416:5) I / Flutter(2601):#18 _RawReceivePortImpl._handleMessage(dart:isolate / runtime / libisolate_patch.dart:171:12) I / flutter(2601):SwiperController发送通知是: I / flutter(2601):“ SwiperController”的实例
依赖性:
flutter_swiper:^ 1.1.4
非常感谢