ANTIPALSU Label template editor using flutter

canvas_setup_page.dart 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_canvas_editor/providers/editor.dart';
  3. import 'package:provider/provider.dart';
  4. class CanvasSetupPage extends StatefulWidget {
  5. @override
  6. _CanvasSetupPageState createState() => _CanvasSetupPageState();
  7. }
  8. class _CanvasSetupPageState extends State<CanvasSetupPage> {
  9. final _formKey = GlobalKey<FormState>();
  10. final TextEditingController _widthController = TextEditingController();
  11. final TextEditingController _heightController = TextEditingController();
  12. @override
  13. void initState() {
  14. // TODO: implement initState
  15. super.initState();
  16. final editorProvider = Provider.of<Editor>(context, listen: false);
  17. _widthController.text = (editorProvider.canvasProperty.width / 10).toString();
  18. _heightController.text = (editorProvider.canvasProperty.height / 10).toString();
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. final editorProvider = Provider.of<Editor>(context);
  23. return Scaffold(
  24. appBar: AppBar(
  25. title: Text('Canvas Setup'),
  26. ),
  27. body: Padding(
  28. padding: const EdgeInsets.all(16.0),
  29. child: Form(
  30. key: _formKey,
  31. child: Column(
  32. children: <Widget>[
  33. Container(
  34. padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
  35. decoration: BoxDecoration(
  36. color: Colors.amber,
  37. borderRadius: BorderRadius.circular(2)
  38. ),
  39. width: double.infinity,
  40. child: Text('Warning Test'),
  41. ),
  42. SizedBox(height: 16),
  43. TextFormField(
  44. controller: _widthController,
  45. decoration: InputDecoration(labelText: 'Width'),
  46. keyboardType: TextInputType.number,
  47. validator: (value) {
  48. if (value == null || value.isEmpty) {
  49. return 'Please enter width';
  50. }
  51. return null;
  52. },
  53. ),
  54. TextFormField(
  55. controller: _heightController,
  56. decoration: InputDecoration(labelText: 'Height'),
  57. keyboardType: TextInputType.number,
  58. validator: (value) {
  59. if (value == null || value.isEmpty) {
  60. return 'Please enter height';
  61. }
  62. return null;
  63. },
  64. ),
  65. SizedBox(height: 20),
  66. ElevatedButton(
  67. onPressed: () async {
  68. if (_formKey.currentState!.validate()) {
  69. // confirmation
  70. final confirmationResult = await showDialog(
  71. barrierDismissible: false,
  72. context: context,
  73. builder: (context) => AlertDialog(
  74. title: Text('Update Label Size'),
  75. content: Text('updating label size will remove all history you have changed, Are you sure want to update label size ?'),
  76. actions: [
  77. TextButton(
  78. onPressed: () => Navigator.pop(context, true),
  79. child: Text('Update label size')
  80. ),
  81. TextButton(
  82. onPressed: () => Navigator.pop(context, false),
  83. child: Text('Cancel')
  84. )
  85. ],
  86. ),
  87. );
  88. if (!confirmationResult) return;
  89. // Process data
  90. editorProvider.updateCanvasProperty(
  91. context,
  92. double.parse(_widthController.text) * 10 ,
  93. double.parse(_heightController.text) * 10
  94. );
  95. Navigator.pop(context);
  96. }
  97. },
  98. child: Text('Submit'),
  99. ),
  100. ],
  101. ),
  102. ),
  103. ),
  104. );
  105. }
  106. }