点击按钮而非滑动滑块提交进度的Flutter游戏开发问题
Flutter游戏模板改造问题:滑块换按钮后main.dart报错
我使用Flutter游戏模板创建测试项目,需求是用户点击特定按钮时,系统记录正确答案并跳转至显示分数与祝贺信息的页面。但将模板中的滑块组件替换为按钮后,main.dart出现报错。
当前按钮实现代码(游戏会话页面)
Consumer<LevelState>( builder: (context, levelState, child) => FilledButton( onPressed: () => GoRouter.of(context).go('/play/won'), style: ButtonStyle( backgroundColor: MaterialStateProperty.resolveWith<Color>( (Set<MaterialState> states) { if (states.contains(MaterialState.pressed)) return Color(0xFF55A318); return Color(0XFFE4DBC8); }, ), ), child: Text('Ostrich bias ${widget.level.difficulty}', style: TextStyle(color: Color(0xFF000000))), ),
原滑块组件代码
Text('Drag the slider to ${widget.level.difficulty}%' ' or above!'), Consumer<LevelState>( builder: (context, levelState, child) => Slider( label: 'Level Progress', autofocus: true, value: levelState.progress / 100, onChanged: (value) => levelState.setProgress((value * 100).round()), onChangeEnd: (value) => levelState.evaluate(), ), ),
报错说明
代码编辑器中按钮相关代码区域显示红色错误提示,存在语法或逻辑问题。
内容的提问来源于stack exchange,提问作者Elena Epshtein
相关产品推荐
相关产品推荐

