我是新的Flutter和块肘。试图学习肘和使用url_launcher包在我的应用程序。我正在使用mealdb的API和去youtube视频与它。我发现youtube链接内的API创建的存储库和一切只是不能得到启动youtube端。我看不到任何在调试控制台也。检查yaml文件url_launcher包它是最新的。
这是我的屏幕侧:
GestureDetector(
onTap: () {
context.read<FoodDetailsCubit>().urlLauncher; }, child: Container(height: 6.h, width: 65.w,
margin: EdgeInsets.only(right: 2.w),
decoration: youtubeBoxDecoration(),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [ Icon(Icons.smart_display_outlined, size: 5.5.h,
color: AppColors.white,),
SizedBox(width: 1.w,),
Text("Watch the Tutorial Video",style: Styles.normalWhiteBoldFontStyle(),)
],
),
),
),
),
肘。省道边:
class FoodDetailsCubit extends Cubit<FoodDetailsState> {
FoodDetailsCubit() : super(FoodDetailsState()) {
loadFoodDetails(52772);
}
final FoodDetailsService api = FoodDetailsService();
Future<void> loadFoodDetails(int foodId) async {
try {
emit(state.copyWith(
foodDetailsStatus: ApiRequest.requestInProgress,
));
final response = (await api.getResFoodDetailsWithId(foodId))?.data;
print(response);
if (response?.meals != null) {
emit(state.copyWith(
foodDetailsStatus: ApiRequest.requestSuccess,
foodDetails: response,
));
} else {
emit(state.copyWith(
foodDetailsStatus: ApiRequest.requestFailure,
));
}
} catch (e) {
emit(state.copyWith(
foodDetailsStatus: ApiRequest.requestFailure,
));
}
}
Future<void> urlLauncher(Uri url) async{
final Uri url = Uri.parse('${state.foodDetails?.meals?[0].strYoutube}');
if (await launchUrl(url)) {
throw 'Could not launch video';
}
}
}
但我按下按钮时什么也没发生。
1条答案
按热度按时间y1aodyip1#
我找到了解决办法:cubit.dart:
视图侧: