【发布时间】:2021-07-30 09:50:25
【问题描述】:
我有一个功能可以从一个屏幕滑动到另一个屏幕,并在我创建的指示条和带有“下一页”选项的提升按钮中显示进度。
我的问题是如何使用 onTap 功能上的提升按钮导航到“下一页”。基本上,与用户向左滑动时的结果相同。
这是我目前所取得的成就:
class xxxx extends State<xxxx> {
final int _numPages = 3;
final PageController _pageController = PageController(initialPage: 0);
int _currentPage = 0;
List<Widget> _buildPageIndicator() {
var list = <Widget>[];
for (var i = 0; i < _numPages; i++) {
list.add(i == _currentPage ? _indicator(true) : _indicator(false));
}
return list;
}
Widget _indicator(bool isActive) {
return AnimatedContainer(
duration: Duration(milliseconds: 150),
margin: EdgeInsets.symmetric(horizontal: 8.0),
height: 8.0,
width: isActive ? 24.0 : 16.0,
decoration: BoxDecoration(
color: isActive ? TheBaseColors.lightRed : Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(12)),
),
);
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
Color background = Color(0xFF001d5d);
return Scaffold(
[...................]
bottomSheet: _currentPage == _numPages - 1
? Container(
height: size.height * 0.10,
color: background,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(children: _buildPageIndicator()),
//CHANGE BUTTON
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: TheBaseColors.lightRed,
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
onPressed: () {
pushNewScreen(
context,
screen: Routes.getWidgetForRoute(Routes.questions, context),
pageTransitionAnimation: PageTransitionAnimation.cupertino,
);
},
child: Text(
'Get started',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.normal,
),
),
),
],
),
)
: Container(
height: size.height * 0.10,
color: background,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(children: _buildPageIndicator()),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: TheBaseColors.lightRed,
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
onPressed: () {
pushNewScreen(
context,
screen: Routes.getWidgetForRoute(Routes.questions, context),
pageTransitionAnimation: PageTransitionAnimation.cupertino,
);
},
child: Text(
'Next',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.normal,
),
),
),
],
),
),
);
}
}
【问题讨论】:
标签: flutter