mirror of
https://github.com/theyakka/qr.flutter.git
synced 2025-05-17 20:55:55 +08:00
100 lines
3.0 KiB
Dart
100 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
class MainScreen extends StatefulWidget {
|
|
@override
|
|
_MainScreenState createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends State<MainScreen> {
|
|
static const double _topSectionTopPadding = 50.0;
|
|
static const double _topSectionBottomPadding = 20.0;
|
|
static const double _topSectionHeight = 50.0;
|
|
|
|
String _dataString = 'Hello from this QR code!';
|
|
String _inputErrorText;
|
|
final TextEditingController _textController = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: _contentWidget(),
|
|
resizeToAvoidBottomPadding: true,
|
|
);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(MainScreen oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
setState(() {});
|
|
}
|
|
|
|
Widget _contentWidget() {
|
|
return Container(
|
|
color: const Color(0xFFFFFFFF),
|
|
child: Column(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
top: _topSectionTopPadding,
|
|
left: 30.0,
|
|
right: 20.0,
|
|
bottom: _topSectionBottomPadding,
|
|
),
|
|
child: Container(
|
|
height: _topSectionHeight,
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.max,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: TextField(
|
|
autofocus: true,
|
|
controller: _textController,
|
|
decoration: InputDecoration(
|
|
hintText: 'Enter a custom message',
|
|
errorText: _inputErrorText,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 10.0),
|
|
child: FlatButton(
|
|
child: const Text('SUBMIT'),
|
|
onPressed: () {
|
|
setState(() {
|
|
_dataString = _textController.text;
|
|
_inputErrorText = null;
|
|
});
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(25.0),
|
|
child: QrImage(
|
|
data: _dataString,
|
|
gapless: false,
|
|
foregroundColor: const Color(0xFF111111),
|
|
onError: (dynamic ex) {
|
|
print('[QR] ERROR - $ex');
|
|
setState(() {
|
|
_inputErrorText =
|
|
'Error! Maybe your input value is too long?';
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|