import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:medcify/constants.dart'; import 'package:medcify/pages/main/qrcode/qr_code_bloc.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../../components/loader.dart'; import '../../../navigation/navigation.dart'; class QrCodePage extends StatelessWidget { const QrCodePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( backgroundColor: Colors.white, elevation: 0.25, automaticallyImplyLeading: false, leading: IconButton( onPressed: (){ Navigation.instance.goBack(); }, icon: const Icon(Icons.keyboard_backspace_rounded,color: Colors.black,), ), title: const Text("Qr Code",style: TextStyle(color: Colors.black,fontSize: 17),), ), body: BlocProvider( create: (context) => QrCodeCubit(), child: QrWidget(), ), ); } } class QrWidget extends StatelessWidget { late QrCodeCubit qrCodeCubit; @override Widget build(BuildContext context) { qrCodeCubit = BlocProvider.of(context); qrCodeCubit.fetchQrCode(); return BlocBuilder( builder: (context, state) { if(state is QrCodeLoading){ return const Loader(); }else if(state is QrCodeFailure){ return Container( alignment: Alignment.center, margin: const EdgeInsets.symmetric(horizontal: 24), child: Text(state.error,style: TextStyle(color: Colors.grey.shade800, fontSize: 13, height: 1.6),), ); }else{ return (qrCodeCubit.image != null) ? Container( alignment: Alignment.center, padding: const EdgeInsets.all(24), child: Column( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: Center( child: Image.memory(qrCodeCubit.image!,) ) ), const SizedBox(height: 24,), MaterialButton( onPressed: () async{ String text = "Hello, ${qrCodeCubit.name} has launched its online pharmacy which lets you order medicines online and get doorstep delivery or self pickup option. To order medicines online , go to "; await launch("https://wa.me/?text=$text${qrCodeCubit.url}"); }, elevation: 0, height: 50, minWidth: double.infinity, color: Constants.primaryColor, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30) ), child: Row( mainAxisSize: MainAxisSize.min, children: const [ ImageIcon(AssetImage("assets/images/whatsapp.png"),color: Colors.white,), SizedBox(width: 8,), Text("Share On Whatsapp",style: TextStyle(color: Colors.white,fontWeight: FontWeight.w600, fontSize: 15),) ], ), ), ], ), ) : const SizedBox(); } } ); } }