[英]Flutter Tab Controller Page Navigation Error
I am making an app and I working on the onboarding screen.我正在制作一个应用程序并在入职屏幕上工作。 When the user finishes answering their questions, I want them the screen to navigate to their user dashboard.
当用户回答完他们的问题后,我希望他们在屏幕上导航到他们的用户仪表板。 I am using a tab controller for the onboarding screen setup, and the problem that I am facing is the final screen not navigating when it is pressed.
我正在使用选项卡 controller 进行入职屏幕设置,我面临的问题是最终屏幕在按下时无法导航。
I receive the following error when I press the button:当我按下按钮时,我收到以下错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/material/tab_controller.dart': Failed assertion: line 181 pos 12: 'value >= 0 && (value < length || length == 0)': is not true. [错误:flutter/lib/ui/ui_dart_state.cc(198)] 未处理的异常:'package:flutter/src/material/tab_controller.dart':断言失败:第 181 行 pos 12:'value >= 0 && (value <长度 || 长度 == 0)': 不正确。
My code is set up to check if the tab controller index is on the last page.我的代码设置为检查选项卡 controller 索引是否在最后一页。 I understand why it is coming up as false;
我明白为什么它是假的; however, I do not know how else to code it to overcome this issue.
但是,我不知道如何编写代码来解决这个问题。 I appreciate any help given:)
感谢您提供的任何帮助:)
Code for button and tab controller:按钮和标签 controller 的代码:
class CustomButton extends StatelessWidget {
final TabController tabController;
const CustomButton({Key? key,
required this.tabController})
: super(key: key);
@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.white
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
vertical: 16),
elevation: 0,
primary: Colors.transparent
),
onPressed: () async{
if (tabController.index == 4) {
Navigator.pushNamed(context, '/dashboard');
}
else {
tabController.animateTo(tabController.index + 1);
}
// await context.read<SignupCubit>().signupWithCredentials();
User user = User(
id: context.read<SignupCubit>().state.user!.uid,
name: '',
age: 0,
imageUrls: [],
Goals: '',
Interests: [],
Focus: []);
},
child: Container(
width: double.infinity,
child: Center(
child: Text('Continue',
style: GoogleFonts.montserrat(
color: const Color.fromARGB(255, 20, 83, 106),
fontSize: 19,
fontWeight: FontWeight.w600
),),
),
)
),
);
}
}
where is your tabbarview?你的tabbarview在哪里? try this steps https://www.woolha.com/tutorials/flutter-using-tabbar-tabbarview-examples
试试这个步骤https://www.woolha.com/tutorials/flutter-using-tabbar-tabbarview-examples
or if you want to understand and implement try this https://youtu.be/apqVp-UjsLg或者如果你想了解和实施试试这个https://youtu.be/apqVp-UjsLg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.