add structure
This commit is contained in:
103
lib/pages/sign.dart
Normal file
103
lib/pages/sign.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_signature_pad/flutter_signature_pad.dart';
|
||||
|
||||
class SignPage extends StatefulWidget {
|
||||
SignPage({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SignPageState createState() => _SignPageState();
|
||||
}
|
||||
|
||||
class _SignPageState extends State<SignPage> {
|
||||
ByteData _img = ByteData(0);
|
||||
var color = Colors.blue;
|
||||
var strokeWidth = 5.0;
|
||||
final _sign = GlobalKey<SignatureState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Text("Driver Signature"),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Signature(
|
||||
color: color,
|
||||
key: _sign,
|
||||
onSign: () {
|
||||
final sign = _sign.currentState;
|
||||
},
|
||||
strokeWidth: strokeWidth,
|
||||
),
|
||||
),
|
||||
color: Colors.black12,
|
||||
),
|
||||
),
|
||||
_img.buffer.lengthInBytes == 0
|
||||
? Container()
|
||||
: LimitedBox(
|
||||
maxHeight: 200.0,
|
||||
child: Image.memory(_img.buffer.asUint8List())),
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: MaterialButton(
|
||||
color: Colors.green,
|
||||
onPressed: () async {
|
||||
final sign = _sign.currentState;
|
||||
final image = await sign.getData();
|
||||
var data = await image.toByteData(
|
||||
format: ui.ImageByteFormat.png);
|
||||
Uint8List buffer = data.buffer.asUint8List();
|
||||
// String path = await _localPath;
|
||||
// File file = await new File(path + "/sign.png")
|
||||
// .writeAsBytes(buffer.asUint8List(
|
||||
// data.offsetInBytes, data.lengthInBytes));
|
||||
Navigator.pop(context, buffer);
|
||||
},
|
||||
child: Text("OK")),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: MaterialButton(
|
||||
color: Colors.grey,
|
||||
onPressed: () {
|
||||
final sign = _sign.currentState;
|
||||
sign.clear();
|
||||
setState(() {
|
||||
_img = ByteData(0);
|
||||
});
|
||||
},
|
||||
child: Text("Clear")),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user