- 我正在尝试在 Flutter 中添加 Liquid Swipe 以进行介绍 Slide it Works Fine
- 它工作正常,但循环无法移动到主页
- 我尝试添加 Navigator.push() 它不起作用
- 我的包裹
liquid_swipe 2.1.0
- 我需要导航到我的
Header()
页面
- 当我单击“跳过”时,它会转到主页(Header())
- 列表项
- 提前致谢
- v2.0.0 迁移到空安全。
我的代码是:
import 'dart:math';
import 'package:abcde/widgets/headers.dart';
import 'package:flutter/material.dart';
import 'package:liquid_swipe/liquid_swipe.dart';
void main() {
/// Comment or uncomment to run both examples
runApp(
WithBuilder(),
//WithPages()
);
}
///Class to hold data for itembuilder in Withbuilder app.
class ItemData {
final Color color;
final String image;
final String text1;
final String text2;
final String text3;
ItemData(this.color, this.image, this.text1, this.text2, this.text3);
}
/// Example of LiquidSwipe with itemBuilder
class WithBuilder extends StatefulWidget {
@override
_WithBuilder createState() => _WithBuilder();
}
class _WithBuilder extends State<WithBuilder> {
int page = 0;
late LiquidController liquidController;
late UpdateType updateType;
List<ItemData> data = [
ItemData(
Colors.blue, 'assets/images/img/gs.jpg', "Hi", "It's Me", "Sahdeep"),
ItemData(Colors.deepPurpleAccent, 'assets/images/img/gs.jpg', "Take a",
"Look At", "Liquid Swipe"),
];
@override
void initState() {
liquidController = LiquidController();
super.initState();
}
Widget _buildDot(int index) {
double selectedness = Curves.easeOut.transform(
max(
0.0,
1.0 - ((page) - index).abs(),
),
);
double zoom = 1.0 + (2.0 - 1.0) * selectedness;
return new Container(
width: 25.0,
child: new Center(
child: new Material(
color: Colors.white,
type: MaterialType.circle,
child: new Container(
width: 8.0 * zoom,
height: 8.0 * zoom,
),
),
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
LiquidSwipe.builder(
itemCount: data.length,
itemBuilder: (context, index) {
return Container(
color: data[index].color,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset(
data[index].image,
fit: BoxFit.cover,
),
Padding(
padding: EdgeInsets.all(20.0),
),
Column(
children: <Widget>[
Text(
data[index].text1,
),
],
),
],
),
);
},
positionSlideIcon: 0.8,
slideIconWidget: Icon(Icons.arrow_back_ios),
onPageChangeCallback: pageChangeCallback,
waveType: WaveType.liquidReveal,
liquidController: liquidController,
ignoreUserGestureWhileAnimating: true,
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Expanded(child: SizedBox()),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(data.length, _buildDot),
),
],
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.all(25.0),
child: FlatButton(
onPressed: () {
liquidController.animateToPage(
page: data.length - 1, duration: 700);
},
child: Text("Skip"),
color: Colors.white.withOpacity(0.01),
),
),
),
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.all(25.0),
child: FlatButton(
onPressed: () {
liquidController.jumpToPage(
page: liquidController.currentPage + 1 > data.length - 1
? 0
: liquidController.currentPage + 1);
},
child: Text("Next"),
color: Colors.white.withOpacity(0.01),
),
),
)
],
),
),
);
}
pageChangeCallback(int lpage) {
setState(() {
page = lpage;
});
}
}