Created
April 4, 2018 12:00
-
-
Save vubon/ca334d6a8291be0c679b8e7c903aec08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
// for generation QR Code | |
import 'package:qr_flutter/qr_flutter.dart'; | |
class QRCodeGenerator extends StatefulWidget{ | |
@override | |
_QRCodeGenerator createState() => new _QRCodeGenerator(); | |
} | |
class _QRCodeGenerator extends State<QRCodeGenerator>{ | |
// static const double _topSectionTopPadding = 50.0; | |
// static const double _topSectionBottomPadding = 20.0; | |
// static const double _topSectionHeight = 50.0; | |
String _dataString = '1'; //= "{'amount': '2000', 'account':'1234578968574859', 'bank': 'Jamuna bank ltd'}"; | |
//String _dataString = "{'amount': '2000', 'account':'1234578968574859', 'bank': 'Jamuna bank ltd', 'connectID': '01737388296', 'type': 'payment', 'hello': 'hello world', 'bkash': 'bkash12354'}"; | |
String _inputErrorText; | |
final TextEditingController _controller = new TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
backgroundColor: Colors.white, | |
appBar: new AppBar( | |
title: new Text("QR Code Generator"), | |
), | |
body: _contentWidget(), | |
resizeToAvoidBottomPadding: true, | |
); | |
} | |
@override | |
didUpdateWidget(Widget oldWidget){ | |
super.didUpdateWidget(oldWidget); | |
setState((){}); | |
} | |
_contentWidget(){ | |
final bodyHeight = MediaQuery.of(context).size.height - MediaQuery.of(context).viewInsets.bottom; | |
return new Column( | |
mainAxisAlignment: MainAxisAlignment.start, | |
children: <Widget>[ | |
new Container( | |
child: new TextFormField( | |
validator: (val) => val.length >= 10 ? 'Amount is too big': null, | |
autofocus: true, | |
controller: _controller, | |
keyboardType: TextInputType.number, | |
//maxLines: 1, | |
decoration: new InputDecoration( | |
hintText: 'Enter Amount', | |
border: new UnderlineInputBorder(), | |
filled: true, | |
icon: new Icon(Icons.attach_money), | |
labelText: "Enter your amount", | |
errorText: _inputErrorText, | |
), | |
), | |
padding: const EdgeInsets.all(20.0), | |
), | |
new Container( | |
child: new RaisedButton( | |
onPressed: () { | |
setState((){ | |
_dataString = _controller.text; | |
_inputErrorText = null; | |
}); | |
// showDialog( | |
// context: context, | |
// child: new AlertDialog( | |
// title: new Text('What you typed'), | |
// content: new Text(_controller.text), | |
// ), | |
// ); | |
}, | |
child: new Text("Generate"), | |
color: Colors.redAccent, | |
textColor: Colors.white, | |
), | |
), | |
new Expanded( | |
child: new Center( | |
child: new QrImage( | |
data: _dataString, | |
size: 0.5 * bodyHeight, | |
version: 15, | |
onError: (ex){ | |
print("QR Erorr - $ex"); | |
setState((){ | |
_inputErrorText = "Error ! message "; | |
}); | |
}, | |
), | |
), | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment