import 'package:flutter/material.dart'; import 'package:teso/Classes/TesoUser.dart'; import 'package:teso/Pages/PageWidgets/CoinPurchase/MomoType.dart'; import 'package:teso/Pages/PageWidgets/CoinPurchase/PayGold.dart'; import 'package:teso/providers/pageAnimations.dart'; import 'package:teso/util/consts.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'PurchaseingSilver.dart'; class SilverPurchaseFixed extends StatefulWidget { final String amount; final String goldCost; final String cashCost; final TesoUser user; const SilverPurchaseFixed( {Key key, this.amount, this.goldCost, this.cashCost, this.user}) : super(key: key); @override _SilverPurchaseFixedState createState() => _SilverPurchaseFixedState(); } class _SilverPurchaseFixedState extends State { TextEditingController momoNumber; String tapped = "goldcoins"; @override void initState() { momoNumber = new TextEditingController(); super.initState(); } void selectTransfer(String type) { setState(() { tapped = type; }); } @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.symmetric( horizontal: (MediaQuery.of(context).size.width) * 0.030, vertical: (MediaQuery.of(context).size.width) * 0.040, ), child: SingleChildScrollView( scrollDirection: Axis.vertical, child: Container( child: new Wrap( children: [ new Container( width: double.infinity, margin: EdgeInsets.only( top: 5.0, bottom: 10.0, ), child: Center( child: Text( "Purchase Silver Coins", style: TextStyle( fontSize: 18.0, ), ), )), Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: Divider(), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 30.0), child: Container( width: MediaQuery.of(context).size.width, margin: EdgeInsets.symmetric(vertical: 5), child: new RichText( text: new TextSpan( style: new TextStyle( fontSize: 15.0, color: Theme.of(context).primaryColorLight, ), children: [ new TextSpan( text: "Purchasing ", ), new TextSpan( text: widget.amount, style: new TextStyle(fontWeight: FontWeight.bold), ), new TextSpan( text: " Silver coins", ), ], ), ), ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 30.0), child: Container( width: double.infinity, margin: EdgeInsets.symmetric(vertical: 5), child: Text( "Payment Method", style: TextStyle( fontSize: 18, ), ), ), ), SizedBox(height: 14.0), Container( color: Colors.transparent, padding: const EdgeInsets.symmetric(horizontal: 20.0), child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: [ payWithGold(context, "goldcoins", selectTransfer, tapped), buildType(context, "assets/images/MTN.png", "mtn", selectTransfer, tapped), buildType(context, "assets/images/Vodafone.png", "vodafone", selectTransfer, tapped), buildType(context, "assets/images/AirtelTigo.png", "airteltigo", selectTransfer, tapped), ], ), ), ), SizedBox(height: 10.0), Visibility( visible: tapped != null ? true : false, child: new Container( margin: EdgeInsets.symmetric( vertical: 20.0, ), child: new Center( child: ElevatedButton( style: ElevatedButton.styleFrom( primary: Theme.of(context).colorScheme.secondary, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(25.0), ), ), ), onPressed: () async { if (tapped == "goldcoins") { Navigator.push( context, PageTransition( child: ProcessSilverPurchase( cost: double.parse(widget.goldCost), method: tapped, silverAmount: int.parse(widget.amount), user: widget.user, ), type: PageTransitionType.leftToRight, ), ); } else { String _url = paymentServer + "purchasesilver/user=${widget.user.userGUID}/amount=${widget.amount}/cointype=TESCNS01"; await canLaunchUrlString(_url) ? await launchUrlString( _url, mode: LaunchMode.platformDefault, ) : throw 'Could not launch $_url'; } }, child: Text( "Confirm", style: TextStyle( color: Colors.white, ), ), ), ), ), ) ], ), ), ), ); } }