123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import 'package:flutter/material.dart';
- import 'package:flutter_canvas_editor/providers/editor.dart';
- import 'package:provider/provider.dart';
- class CanvasSetupPage extends StatefulWidget {
- @override
- _CanvasSetupPageState createState() => _CanvasSetupPageState();
- }
- class _CanvasSetupPageState extends State<CanvasSetupPage> {
- final _formKey = GlobalKey<FormState>();
- final TextEditingController _widthController = TextEditingController();
- final TextEditingController _heightController = TextEditingController();
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- final editorProvider = Provider.of<Editor>(context, listen: false);
- _widthController.text = editorProvider.canvasProperty.width.toString();
- _heightController.text = editorProvider.canvasProperty.height.toString();
- }
- @override
- Widget build(BuildContext context) {
- final editorProvider = Provider.of<Editor>(context);
- return Scaffold(
- appBar: AppBar(
- title: Text('Canvas Setup'),
- ),
- body: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Form(
- key: _formKey,
- child: Column(
- children: <Widget>[
- Container(
- padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
- decoration: BoxDecoration(
- color: Colors.amber,
- borderRadius: BorderRadius.circular(2)
- ),
- width: double.infinity,
- child: Text('Warning Test'),
- ),
- SizedBox(height: 16),
- TextFormField(
- controller: _widthController,
- decoration: InputDecoration(labelText: 'Width'),
- keyboardType: TextInputType.number,
- validator: (value) {
- if (value == null || value.isEmpty) {
- return 'Please enter width';
- }
- return null;
- },
- ),
- TextFormField(
- controller: _heightController,
- decoration: InputDecoration(labelText: 'Height'),
- keyboardType: TextInputType.number,
- validator: (value) {
- if (value == null || value.isEmpty) {
- return 'Please enter height';
- }
- return null;
- },
- ),
- SizedBox(height: 20),
- ElevatedButton(
- onPressed: () async {
- if (_formKey.currentState!.validate()) {
- // confirmation
- final confirmationResult = await showDialog(
- barrierDismissible: false,
- context: context,
- builder: (context) => AlertDialog(
- title: Text('Update Label Size'),
- content: Text('updating to smaller label size may cause element lost, Are you sure want to update label size ?'),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(context, true),
- child: Text('Update label size')
- ),
- TextButton(
- onPressed: () => Navigator.pop(context, false),
- child: Text('Cancel')
- )
- ],
- ),
- );
- if (!confirmationResult) return;
-
- // Process data
- editorProvider.updateCanvasProperty(
- context,
- double.parse(_widthController.text) ,
- double.parse(_heightController.text)
- );
- Navigator.pop(context);
- }
- },
- child: Text('Submit'),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|