import 'package:flutter/material.dart'; import 'package:invoiceninja_flutter/ui/app/edit_scaffold.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart'; import 'package:invoiceninja_flutter/ui/stub/edit/stub_edit_vm.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/ui/app/scrollable_listview.dart'; class StubEdit extends StatefulWidget { const StubEdit({ Key key, @required this.viewModel, }) : super(key: key); final StubEditVM viewModel; @override _StubEditState createState() => _StubEditState(); } class _StubEditState extends State { static final GlobalKey _formKey = GlobalKey(debugLabel: '_stubEdit'); final _debouncer = Debouncer(); // STARTER: controllers - do not remove comment List _controllers = []; @override void didChangeDependencies() { _controllers = [ // STARTER: array - do not remove comment ]; _controllers.forEach((controller) => controller.removeListener(_onChanged)); final stub = widget.viewModel.stub; // STARTER: read value - do not remove comment _controllers.forEach((controller) => controller.addListener(_onChanged)); super.didChangeDependencies(); } @override void dispose() { _controllers.forEach((controller) { controller.removeListener(_onChanged); controller.dispose(); }); super.dispose(); } void _onChanged() { _debouncer.run(() { final stub = widget.viewModel.stub.rebuild((b) => b // STARTER: set value - do not remove comment ); if (stub != widget.viewModel.stub) { widget.viewModel.onChanged(stub); } }); } @override Widget build(BuildContext context) { final viewModel = widget.viewModel; final localization = AppLocalization.of(context); final stub = viewModel.stub; return EditScaffold( title: stub.isNew ? localization.newStub : localization.editStub, onCancelPressed: (context) => viewModel.onCancelPressed(context), onSavePressed: (context) { final bool isValid = _formKey.currentState.validate(); if (!isValid) { return; } viewModel.onSavePressed(context); }, body:Form( key: _formKey, child: Builder(builder: (BuildContext context) { return ScrollableListView( children: [ FormCard( children: [ // STARTER: widgets - do not remove comment ], ), ], ); }) ), ); } }