import 'package:flutter/material.dart';import 'package:flutter/cupertino.dart';import 'package:carousel_pro/carousel_pro.dart';import '../plug/wlist.dart';class BodyPage extends StatefulWidget { final int tid; BodyPage({Key key, this.tid}) : super(key: key); @override StatecreateState() => new BodyPageState();}class BodyPageState extends State { final PageController _pageController=new PageController(); double _currentPage = 0.0; @override void initState() { // TODO: implement initState super.initState(); _pageController.addListener((){ print(_pageController); print(_pageController.offset); }); } @override void dispose() { // TODO: implement dispose super.dispose(); _pageController.dispose(); }// new PageView(// physics: const PageScrollPhysics(parent: const BouncingScrollPhysics()),// onPageChanged: (index){// print(index);// },// controller: _pageController,// children: [// new Container(// height: 200.0,// color: Colors.blue,// child: new Text('11')),// new Container(// height: 200.0,// color: Colors.purple,// child: new Text('22')),// new Container(// height: 200.0,// color: Colors.deepPurpleAccent,// child: new Text('3')),// ],// ) final String data; final double parallaxOffset=0.0; dom({data:"",parallaxOffset:0.0}){ return new Center( child: new Column( mainAxisSize: MainAxisSize.min, children: [ new Text( data, style: const TextStyle(fontSize: 60.0), ), new SizedBox(height: 40.0), new Transform( transform: new Matrix4.translationValues(parallaxOffset, 0.0, 0.0), child: const Text('Yet another line of text'), ), ], ), ); } @override Widget build(BuildContext context) { print(MediaQuery.of(context).size.width - 30); return new ListView( padding: EdgeInsets.only(top: 0.0), children: [ new Container( margin: EdgeInsets.all(15.0), height: 200.0, child: new SizedBox( height: 200.0, child:new LayoutBuilder(builder: (context, constraints) => new NotificationListener( onNotification: (ScrollNotification note) { setState(() { _currentPage = _pageController.page; }); }, child: new PageView.custom( physics: const PageScrollPhysics(parent: const BouncingScrollPhysics()), controller: _pageController, childrenDelegate: new SliverChildBuilderDelegate( //生成widget (context, index){ print("当前距离:${_currentPage}"); //当前widget 的狂傲 return dom(data:"ww{$index}",parallaxOffset:constraints.maxWidth / 1.0 * (index - _currentPage)); }, childCount: 2,//个数 ), ), )), ), ), new Divider(), new WlistPage(), ], ); }}