From 4e1ce3a1868f912f59b8acfbeafcda9f0cbaabcd Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Mon, 26 Oct 2020 22:50:56 +0100 Subject: [PATCH] daily work --- lib/app.dart | 1 - lib/src/model/db_reference_model.dart | 3 + lib/src/model/page_model.dart | 22 +++- .../model/standard/configuration_model.dart | 2 + lib/src/model/standard/role_model.dart | 2 + lib/src/model/standard/user_model.dart | 2 + lib/src/model/table_model.dart | 2 - lib/src/page/application_data.dart | 22 ++++ .../configuration_change_page.dart | 36 +++++-- .../configuration_controller.dart | 27 +++-- .../configuration_create_page.dart | 18 ++-- .../configuration_list_page.dart | 62 ++++------- lib/src/page/role/role_change_page.dart | 25 +++-- lib/src/page/role/role_controller.dart | 5 +- lib/src/page/role/role_create_page.dart | 10 +- lib/src/page/role/role_list_page.dart | 30 ++++-- lib/src/page/user/user_change_page.dart | 35 ++++-- lib/src/page/user/user_controller.dart | 20 ++-- lib/src/page/user/user_create_page.dart | 17 ++- lib/src/page/user/user_list_page.dart | 59 ++++------ lib/src/private/bdrawer.dart | 7 +- lib/src/widget/callback_controller_bones.dart | 40 +++++-- lib/src/widget/checkbox_form_field.dart | 1 - lib/src/widget/edit_form.dart | 5 +- lib/src/widget/list_form.dart | 8 +- lib/src/widget/page_controller_bones.dart | 102 ++++++++++++------ lib/src/widget/view.dart | 50 +++++---- lib/src/widget/widget_list.dart | 4 +- test/model/db_model_test.dart | 2 +- test/model/model_test.dart | 8 +- test/widget/widget_test.dart | 16 +-- 31 files changed, 401 insertions(+), 242 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 0f6d5e8..cb4cf07 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'src/helper/settings.dart'; import 'src/page/login_page.dart'; -import 'src/page/role/role_change_page.dart'; import 'src/page/role/role_create_page.dart'; import 'src/page/role/role_list_page.dart'; import 'src/private/bsettings.dart'; diff --git a/lib/src/model/db_reference_model.dart b/lib/src/model/db_reference_model.dart index f93faba..785e0db 100644 --- a/lib/src/model/db_reference_model.dart +++ b/lib/src/model/db_reference_model.dart @@ -37,6 +37,9 @@ class DbReferenceModel extends FieldModel { this.column = column; maxSize = column.size; rows = column.rows; + if (column.hasOption('primary') && ! column.hasOption('readonly')){ + options.add('readonly'); + } } /// Dumps the internal structure into a [stringBuffer] diff --git a/lib/src/model/page_model.dart b/lib/src/model/page_model.dart index 858c0b4..6df201e 100644 --- a/lib/src/model/page_model.dart +++ b/lib/src/model/page_model.dart @@ -20,6 +20,8 @@ class PageModel extends ModelBase { final fields = []; final buttons = []; final widgets = []; + List tableTitles; + List tableColumns; PageModel(this.module, this.map, BaseLogger logger) : super(logger); @@ -58,7 +60,7 @@ class PageModel extends ModelBase { final name = field.name; if (hasField(name)) { logger.error('field ${field.fullName()} already defined: ' + - getField(name).fullName()); + fieldByName(name).fullName()); } else { fields.add(field); } @@ -79,7 +81,7 @@ class PageModel extends ModelBase { String fullName() => '${module.name}.$name'; /// Returns a field by [name] or null on error. - FieldModel getField(String name, {bool required = true}) { + FieldModel fieldByName(String name, {bool required = true}) { final rc = fields.firstWhere((element) => element.name == name, orElse: () => null); if (required && rc == null) { @@ -106,7 +108,7 @@ class PageModel extends ModelBase { void parse() { name = parseString('page', map, required: true); checkSuperfluousAttributes( - map, 'options page pageType sections'.split(' ')); + map, 'options page pageType sections tableColumns tableTitles'.split(' ')); pageModelType = parseEnum( 'pageType', map, PageModelType.values, required: true); @@ -122,6 +124,20 @@ class PageModel extends ModelBase { SectionModel.parseSections(this, null, item, logger); } } + tableTitles = parseStringList('tableTitles', map); + tableColumns = parseString('tableColumns', map)?.split(' '); + if (pageModelType != PageModelType.list && + (tableTitles != null || tableColumns != null)) { + logger.error( + 'tableTitles and tableColumns are only meaningful in list pages: ${fullName()}'); + } + if (tableTitles != null && + tableColumns != null && + tableTitles.length != tableColumns.length) { + logger.error( + 'different sizes of tableTitles/tableColumns: ${tableTitles.length}/${tableColumns.length}'); + } + if (!options.contains('noAutoButton') && buttonByName('search', required: false) == null) { final section = null; diff --git a/lib/src/model/standard/configuration_model.dart b/lib/src/model/standard/configuration_model.dart index a9534db..2351d9d 100644 --- a/lib/src/model/standard/configuration_model.dart +++ b/lib/src/model/standard/configuration_model.dart @@ -89,6 +89,8 @@ class ConfigurationModel extends ModuleModel { { "page": "list", "pageType": "list", + "tableColumns": "configuration_id configuration_scope configuration_property configuration_order configuration_value configuration_type", + "tableTitles": ";Id;Bereich;Eigenschaft;Reihe;Wert;Typ", "sections": [ { "sectionType": "filterPanel", diff --git a/lib/src/model/standard/role_model.dart b/lib/src/model/standard/role_model.dart index 32af803..3a1f642 100644 --- a/lib/src/model/standard/role_model.dart +++ b/lib/src/model/standard/role_model.dart @@ -67,6 +67,8 @@ class RoleModel extends ModuleModel { { "page": "list", "pageType": "list", + "tableColumns": "role_id role_name role_prio", + "tableTitles": ";Id;Rolle;Priorität", "sections": [ { "sectionType": "filterPanel", diff --git a/lib/src/model/standard/user_model.dart b/lib/src/model/standard/user_model.dart index a8b0c54..3aa5c50 100644 --- a/lib/src/model/standard/user_model.dart +++ b/lib/src/model/standard/user_model.dart @@ -84,6 +84,8 @@ class UserModel extends ModuleModel { { "page": "list", "pageType": "list", + "tableColumns": "user_id user_name user_displayname user_email user_role", + "tableTitles": ";Id;Name;Anzeigename;EMail;Rolle", "sections": [ { "sectionType": "filterPanel", diff --git a/lib/src/model/table_model.dart b/lib/src/model/table_model.dart index e1753d6..1ca2002 100644 --- a/lib/src/model/table_model.dart +++ b/lib/src/model/table_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:meta/meta.dart'; import 'column_model.dart'; import 'model_base.dart'; @@ -13,7 +12,6 @@ class TableModel extends ModelBase { final Map map; String name; List options; - @protected final columns = []; ColumnModel primary; diff --git a/lib/src/page/application_data.dart b/lib/src/page/application_data.dart index 99b1dc1..75b6e58 100644 --- a/lib/src/page/application_data.dart +++ b/lib/src/page/application_data.dart @@ -1,6 +1,8 @@ import 'package:dart_bones/dart_bones.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; +import 'package:flutter_bones/src/widget/page_controller_bones.dart'; /// Data class for storing parameter to build a page. class ApplicationData { @@ -13,6 +15,10 @@ class ApplicationData { final Persistence persistence; String currentUser; int currentRoleId; + /// for unittests: + dynamic lastModuleState; + @protected + final callerStack = []; /// Constructor. /// [configuration] is a map with the widget data (e.g. padding) @@ -23,4 +29,20 @@ class ApplicationData { currentUser = 'Gast'; currentRoleId = 100; } + /// Enforces a redraw of the caller of the current page. + /// [reason] specifies why the redraw is needed and [customString] + /// is an additional info for the reason. + void callerRedraw(RedrawReason reason, [String customString]){ + if (callerStack.isNotEmpty && callerStack.last != null){ + callerStack.last.redraw(reason, customString); + } + } + void pushCaller(PageControllerBones controller){ + callerStack.add(controller); + } + void popCaller(){ + if (callerStack.isNotEmpty){ + callerStack.removeLast(); + } + } } diff --git a/lib/src/page/configuration/configuration_change_page.dart b/lib/src/page/configuration/configuration_change_page.dart index 55c0e60..e8c0289 100644 --- a/lib/src/page/configuration/configuration_change_page.dart +++ b/lib/src/page/configuration/configuration_change_page.dart @@ -1,40 +1,52 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/edit_form.dart'; import 'configuration_controller.dart'; class ConfigurationChangePage extends StatefulWidget { final ApplicationData applicationData; + final Map initialRow; final logger = Settings().logger; - + final int primaryId; //ConfigurationChangePageState lastState; - ConfigurationChangePage(this.applicationData, {Key key}) : super(key: key); + ConfigurationChangePage(this.primaryId, this.applicationData, this.initialRow, + {Key key}) + : super(key: key); @override ConfigurationChangePageState createState() { - final rc = ConfigurationChangePageState(applicationData); - // lastState = rc; + final rc = ConfigurationChangePageState(primaryId, applicationData, initialRow); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } class ConfigurationChangePageState extends State { final ApplicationData applicationData; - + final int primaryId; + final Map initialRow; final GlobalKey _formKey = GlobalKey(debugLabel: 'configuration_change'); ConfigurationController controller; - ConfigurationChangePageState(this.applicationData); + ConfigurationChangePageState(this.primaryId, this.applicationData, this.initialRow); @override Widget build(BuildContext context) { - controller = controller ?? - ConfigurationController( - _formKey, this, 'change', context, applicationData); + if (controller == null) { + controller = ConfigurationController( + _formKey, this, 'change', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) => + setState(() => null)); + controller.initialize(); + } + // controller.buildWidgetList() is called in editForm return Scaffold( appBar: applicationData.appBarBuilder('Rolle ändern'), drawer: applicationData.drawerBuilder(context), @@ -42,6 +54,12 @@ class ConfigurationChangePageState extends State { key: _formKey, pageController: controller, configuration: applicationData.configuration, + primaryId: primaryId, + initialRow: initialRow, )); } + void dispose() { + controller.dispose(); + super.dispose(); + } } diff --git a/lib/src/page/configuration/configuration_controller.dart b/lib/src/page/configuration/configuration_controller.dart index 27af1e1..7b9eb09 100644 --- a/lib/src/page/configuration/configuration_controller.dart +++ b/lib/src/page/configuration/configuration_controller.dart @@ -2,25 +2,22 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; import '../../model/standard/configuration_model.dart'; +import 'configuration_change_page.dart'; import '../../widget/page_controller_bones.dart'; class ConfigurationController extends PageControllerBones { /// Controller for a page named [pageName]. - ConfigurationController( - GlobalKey formKey, - State parent, - String pageName, - BuildContext context, - ApplicationData applicationData, - {Function fetchRows}) - : super( - formKey, - parent, - ConfigurationModel(Settings().logger), - pageName, - context, - applicationData, - ) { + ConfigurationController(GlobalKey formKey, State parent, + String pageName, BuildContext context, ApplicationData applicationData, + {Function redrawCallback}) + : super(formKey, parent, ConfigurationModel(Settings().logger), pageName, context, + applicationData, redrawCallback) { moduleModel.parse(); } + @override + void startChange(int id, Map row) { + applicationData.pushCaller(this); + Navigator.push(context, + MaterialPageRoute(builder: (context) => ConfigurationChangePage(id, applicationData, row))); + } } diff --git a/lib/src/page/configuration/configuration_create_page.dart b/lib/src/page/configuration/configuration_create_page.dart index 6e6b0d3..331a57b 100644 --- a/lib/src/page/configuration/configuration_create_page.dart +++ b/lib/src/page/configuration/configuration_create_page.dart @@ -5,14 +5,17 @@ import '../../widget/edit_form.dart'; import 'configuration_controller.dart'; class ConfigurationCreatePage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; final logger = Settings().logger; - ConfigurationCreatePage(this.pageData, {Key key}) : super(key: key); + ConfigurationCreatePage(this.applicationData, {Key key}) : super(key: key); @override ConfigurationCreatePageState createState() { - final rc = ConfigurationCreatePageState(pageData); + final rc = ConfigurationCreatePageState(applicationData); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -29,9 +32,12 @@ class ConfigurationCreatePageState extends State { @override Widget build(BuildContext context) { - controller = controller ?? - ConfigurationController( - _formKey, this, 'create', context, applicationData); + if (controller == null) { + controller = + ConfigurationController(_formKey, this, 'create', context, applicationData); + controller.initialize(); + } + controller.buildWidgetList(); return Scaffold( appBar: applicationData.appBarBuilder('Neue Rolle'), drawer: applicationData.drawerBuilder(context), diff --git a/lib/src/page/configuration/configuration_list_page.dart b/lib/src/page/configuration/configuration_list_page.dart index 57d9ac6..e42bab4 100644 --- a/lib/src/page/configuration/configuration_list_page.dart +++ b/lib/src/page/configuration/configuration_list_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/filter_set.dart'; import '../../widget/list_form.dart'; @@ -6,15 +7,16 @@ import '../application_data.dart'; import 'configuration_controller.dart'; class ConfigurationListPage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; - ConfigurationListPage(this.pageData, {Key key}) : super(key: key); + ConfigurationListPage(this.applicationData, {Key key}) : super(key: key); @override ConfigurationListPageState createState() { // ConfigurationListPageState.setPageData(pageData); - final rc = ConfigurationListPageState(pageData); - + final rc = ConfigurationListPageState(applicationData); + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -24,7 +26,7 @@ class ConfigurationListPageState extends State { final GlobalKey _formKey = GlobalKey(debugLabel: 'configuration_list'); - Iterable rows; + Iterable rowsDeprecated; ConfigurationController controller; FilterSet filters; @@ -32,38 +34,36 @@ class ConfigurationListPageState extends State { @override Widget build(BuildContext context) { - controller ??= ConfigurationController( - _formKey, this, 'list', context, applicationData); + if (controller == null) { + controller = ConfigurationController( + _formKey, this, 'list', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) => setState(() => null)); + controller.initialize(); + controller.buildWidgetList(); + } filters ??= controller.filterSet(pageName: 'list'); - getRows(); + controller.buildRows(); return Scaffold( appBar: applicationData.appBarBuilder('Rollen'), drawer: applicationData.drawerBuilder(context), body: ListForm.listForm( key: _formKey, configuration: applicationData.configuration, - titles: ListForm.stringsToTitles(';Id;Name;Priorität'), - columnNames: - 'configuration_id configuration_name configuration_priority' - .split(' '), - rows: rows ?? [], + titles: ListForm.stringsToTitles(controller.page.tableTitles), + columnNames: controller.page.tableColumns ?? [], + rows: controller.listRows ?? [], showEditIcon: true, + pageController: controller, buttons: [ ButtonBar(alignment: MainAxisAlignment.center, children: [ - RaisedButton( - child: Text('Suchen'), - onPressed: () { - rows = null; - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); - getRows(); - } - }, - ), + controller.searchButton(), RaisedButton( child: Text('Neue Rolle'), onPressed: () { Navigator.pushNamed(context, '/configuration/create'); + + /// Force the redraw on return: + controller.listRows = null; }, ), ]), @@ -72,20 +72,4 @@ class ConfigurationListPageState extends State { ), ); } - - void getRows() { - final persistence = applicationData.persistence; - final namePattern = filters.valueOf('configuration_name') ?? ''; - persistence.list(module: 'configuration', params: { - ':configuration_name': namePattern.replaceAll('*', '%') + '%' - }).then((list) { - if (rows == null) { - rows = list; - setState(() {}); - } - }, onError: (error) { - applicationData.logger - .error('cannot retrieve configuration list: $error'); - }); - } } diff --git a/lib/src/page/role/role_change_page.dart b/lib/src/page/role/role_change_page.dart index 5ee94d7..8c65cf3 100644 --- a/lib/src/page/role/role_change_page.dart +++ b/lib/src/page/role/role_change_page.dart @@ -1,22 +1,27 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/edit_form.dart'; import 'role_controller.dart'; class RoleChangePage extends StatefulWidget { final ApplicationData applicationData; + final Map initialRow; final logger = Settings().logger; final int primaryId; //RoleChangePageState lastState; - RoleChangePage(this.primaryId, this.applicationData, {Key key}) + RoleChangePage(this.primaryId, this.applicationData, this.initialRow, + {Key key}) : super(key: key); @override RoleChangePageState createState() { - final rc = RoleChangePageState(primaryId, applicationData); - // lastState = rc; + final rc = RoleChangePageState(primaryId, applicationData, initialRow); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -24,21 +29,24 @@ class RoleChangePage extends StatefulWidget { class RoleChangePageState extends State { final ApplicationData applicationData; final int primaryId; + final Map initialRow; final GlobalKey _formKey = GlobalKey(debugLabel: 'role_change'); RoleController controller; - RoleChangePageState(this.primaryId, this.applicationData); + RoleChangePageState(this.primaryId, this.applicationData, this.initialRow); @override Widget build(BuildContext context) { if (controller == null) { controller = RoleController( - _formKey, this, 'list', context, applicationData, - redrawCallback: () => setState(() => null)); + _formKey, this, 'change', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) => + setState(() => null)); controller.initialize(); } + // controller.buildWidgetList() is called in editForm return Scaffold( appBar: applicationData.appBarBuilder('Rolle ändern'), drawer: applicationData.drawerBuilder(context), @@ -47,6 +55,11 @@ class RoleChangePageState extends State { pageController: controller, configuration: applicationData.configuration, primaryId: primaryId, + initialRow: initialRow, )); } + void dispose() { + controller.dispose(); + super.dispose(); + } } diff --git a/lib/src/page/role/role_controller.dart b/lib/src/page/role/role_controller.dart index 2bfa22c..3aff56f 100644 --- a/lib/src/page/role/role_controller.dart +++ b/lib/src/page/role/role_controller.dart @@ -15,8 +15,9 @@ class RoleController extends PageControllerBones { moduleModel.parse(); } @override - void startChange(int id) { + void startChange(int id, Map row) { + applicationData.pushCaller(this); Navigator.push(context, - MaterialPageRoute(builder: (context) => RoleChangePage(id, applicationData))); + MaterialPageRoute(builder: (context) => RoleChangePage(id, applicationData, row))); } } diff --git a/lib/src/page/role/role_create_page.dart b/lib/src/page/role/role_create_page.dart index 3017487..875bea9 100644 --- a/lib/src/page/role/role_create_page.dart +++ b/lib/src/page/role/role_create_page.dart @@ -5,14 +5,17 @@ import '../../widget/edit_form.dart'; import 'role_controller.dart'; class RoleCreatePage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; final logger = Settings().logger; - RoleCreatePage(this.pageData, {Key key}) : super(key: key); + RoleCreatePage(this.applicationData, {Key key}) : super(key: key); @override RoleCreatePageState createState() { - final rc = RoleCreatePageState(pageData); + final rc = RoleCreatePageState(applicationData); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -34,6 +37,7 @@ class RoleCreatePageState extends State { RoleController(_formKey, this, 'create', context, applicationData); controller.initialize(); } + controller.buildWidgetList(); return Scaffold( appBar: applicationData.appBarBuilder('Neue Rolle'), drawer: applicationData.drawerBuilder(context), diff --git a/lib/src/page/role/role_list_page.dart b/lib/src/page/role/role_list_page.dart index e27f868..6b85f50 100644 --- a/lib/src/page/role/role_list_page.dart +++ b/lib/src/page/role/role_list_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/filter_set.dart'; import '../../widget/list_form.dart'; @@ -6,15 +7,17 @@ import '../application_data.dart'; import 'role_controller.dart'; class RoleListPage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; - RoleListPage(this.pageData, {Key key}) : super(key: key); + RoleListPage(this.applicationData, {Key key}) : super(key: key); @override RoleListPageState createState() { // RoleListPageState.setPageData(pageData); - final rc = RoleListPageState(pageData); + final rc = RoleListPageState(applicationData); + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -33,10 +36,21 @@ class RoleListPageState extends State { @override Widget build(BuildContext context) { if (controller == null) { - controller = RoleController( - _formKey, this, 'list', context, applicationData, - redrawCallback: () => setState(() => null)); + controller = + RoleController(_formKey, this, 'list', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) { + if (reason == RedrawReason.fetchList) { + applicationData.persistence + .list( + module: controller.moduleModel.name, + params: controller.buildSqlParams()) + .then((rows) { + setState(() => null); + }); + } + }); controller.initialize(); + controller.buildWidgetList(); } filters ??= controller.filterSet(pageName: 'list'); controller.buildRows(); @@ -46,8 +60,8 @@ class RoleListPageState extends State { body: ListForm.listForm( key: _formKey, configuration: applicationData.configuration, - titles: ListForm.stringsToTitles(';Id;Name;Priorität'), - columnNames: 'role_id role_name role_priority'.split(' '), + titles: ListForm.stringsToTitles(controller.page.tableTitles), + columnNames: controller.page.tableColumns ?? [], rows: controller.listRows ?? [], showEditIcon: true, pageController: controller, diff --git a/lib/src/page/user/user_change_page.dart b/lib/src/page/user/user_change_page.dart index 50f2cab..c548fa1 100644 --- a/lib/src/page/user/user_change_page.dart +++ b/lib/src/page/user/user_change_page.dart @@ -1,39 +1,52 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/edit_form.dart'; import 'user_controller.dart'; class UserChangePage extends StatefulWidget { final ApplicationData applicationData; + final Map initialRow; final logger = Settings().logger; - + final int primaryId; //UserChangePageState lastState; - UserChangePage(this.applicationData, {Key key}) : super(key: key); + UserChangePage(this.primaryId, this.applicationData, this.initialRow, + {Key key}) + : super(key: key); @override UserChangePageState createState() { - final rc = UserChangePageState(applicationData); - // lastState = rc; + final rc = UserChangePageState(primaryId, applicationData, initialRow); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } class UserChangePageState extends State { final ApplicationData applicationData; - + final int primaryId; + final Map initialRow; final GlobalKey _formKey = GlobalKey(debugLabel: 'user_change'); UserController controller; - UserChangePageState(this.applicationData); + UserChangePageState(this.primaryId, this.applicationData, this.initialRow); @override Widget build(BuildContext context) { - controller = controller ?? - UserController(_formKey, this, 'change', context, applicationData); + if (controller == null) { + controller = UserController( + _formKey, this, 'change', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) => + setState(() => null)); + controller.initialize(); + } + // controller.buildWidgetList() is called in editForm return Scaffold( appBar: applicationData.appBarBuilder('Rolle ändern'), drawer: applicationData.drawerBuilder(context), @@ -41,6 +54,12 @@ class UserChangePageState extends State { key: _formKey, pageController: controller, configuration: applicationData.configuration, + primaryId: primaryId, + initialRow: initialRow, )); } + void dispose() { + controller.dispose(); + super.dispose(); + } } diff --git a/lib/src/page/user/user_controller.dart b/lib/src/page/user/user_controller.dart index 22db524..9358424 100644 --- a/lib/src/page/user/user_controller.dart +++ b/lib/src/page/user/user_controller.dart @@ -2,20 +2,22 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; import '../../model/standard/user_model.dart'; +import 'user_change_page.dart'; import '../../widget/page_controller_bones.dart'; class UserController extends PageControllerBones { /// Controller for a page named [pageName]. UserController(GlobalKey formKey, State parent, - String pageName, BuildContext context, ApplicationData applicationData) - : super( - formKey, - parent, - UserModel(Settings().logger), - pageName, - context, - applicationData, - ) { + String pageName, BuildContext context, ApplicationData applicationData, + {Function redrawCallback}) + : super(formKey, parent, UserModel(Settings().logger), pageName, context, + applicationData, redrawCallback) { moduleModel.parse(); } + @override + void startChange(int id, Map row) { + applicationData.pushCaller(this); + Navigator.push(context, + MaterialPageRoute(builder: (context) => UserChangePage(id, applicationData, row))); + } } diff --git a/lib/src/page/user/user_create_page.dart b/lib/src/page/user/user_create_page.dart index eada475..0837ca8 100644 --- a/lib/src/page/user/user_create_page.dart +++ b/lib/src/page/user/user_create_page.dart @@ -5,14 +5,17 @@ import '../../widget/edit_form.dart'; import 'user_controller.dart'; class UserCreatePage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; final logger = Settings().logger; - UserCreatePage(this.pageData, {Key key}) : super(key: key); + UserCreatePage(this.applicationData, {Key key}) : super(key: key); @override UserCreatePageState createState() { - final rc = UserCreatePageState(pageData); + final rc = UserCreatePageState(applicationData); + + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -29,8 +32,12 @@ class UserCreatePageState extends State { @override Widget build(BuildContext context) { - controller = controller ?? - UserController(_formKey, this, 'create', context, applicationData); + if (controller == null) { + controller = + UserController(_formKey, this, 'create', context, applicationData); + controller.initialize(); + } + controller.buildWidgetList(); return Scaffold( appBar: applicationData.appBarBuilder('Neue Rolle'), drawer: applicationData.drawerBuilder(context), diff --git a/lib/src/page/user/user_list_page.dart b/lib/src/page/user/user_list_page.dart index 55ba74e..2715dac 100644 --- a/lib/src/page/user/user_list_page.dart +++ b/lib/src/page/user/user_list_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bones/src/widget/callback_controller_bones.dart'; import '../../widget/filter_set.dart'; import '../../widget/list_form.dart'; @@ -6,15 +7,16 @@ import '../application_data.dart'; import 'user_controller.dart'; class UserListPage extends StatefulWidget { - final ApplicationData pageData; + final ApplicationData applicationData; - UserListPage(this.pageData, {Key key}) : super(key: key); + UserListPage(this.applicationData, {Key key}) : super(key: key); @override UserListPageState createState() { // UserListPageState.setPageData(pageData); - final rc = UserListPageState(pageData); - + final rc = UserListPageState(applicationData); + /// for unittests: + applicationData.lastModuleState = rc; return rc; } } @@ -24,7 +26,7 @@ class UserListPageState extends State { final GlobalKey _formKey = GlobalKey(debugLabel: 'user_list'); - Iterable rows; + Iterable rowsDeprecated; UserController controller; FilterSet filters; @@ -32,36 +34,36 @@ class UserListPageState extends State { @override Widget build(BuildContext context) { - controller ??= - UserController(_formKey, this, 'list', context, applicationData); + if (controller == null) { + controller = UserController( + _formKey, this, 'list', context, applicationData, + redrawCallback: (RedrawReason reason, String customString) => setState(() => null)); + controller.initialize(); + controller.buildWidgetList(); + } filters ??= controller.filterSet(pageName: 'list'); - getRows(); + controller.buildRows(); return Scaffold( appBar: applicationData.appBarBuilder('Rollen'), drawer: applicationData.drawerBuilder(context), body: ListForm.listForm( key: _formKey, configuration: applicationData.configuration, - titles: ListForm.stringsToTitles(';Id;Name;Priorität'), - columnNames: 'user_id user_name user_priority'.split(' '), - rows: rows ?? [], + titles: ListForm.stringsToTitles(controller.page.tableTitles), + columnNames: controller.page.tableColumns ?? [], + rows: controller.listRows ?? [], showEditIcon: true, + pageController: controller, buttons: [ ButtonBar(alignment: MainAxisAlignment.center, children: [ - RaisedButton( - child: Text('Suchen'), - onPressed: () { - rows = null; - if (_formKey.currentState.validate()) { - _formKey.currentState.save(); - getRows(); - } - }, - ), + controller.searchButton(), RaisedButton( child: Text('Neue Rolle'), onPressed: () { Navigator.pushNamed(context, '/user/create'); + + /// Force the redraw on return: + controller.listRows = null; }, ), ]), @@ -70,19 +72,4 @@ class UserListPageState extends State { ), ); } - - void getRows() { - final persistence = applicationData.persistence; - final namePattern = filters.valueOf('user_name') ?? ''; - persistence.list(module: 'user', params: { - ':user_name': namePattern.replaceAll('*', '%') + '%' - }).then((list) { - if (rows == null) { - rows = list; - setState(() {}); - } - }, onError: (error) { - applicationData.logger.error('cannot retrieve user list: $error'); - }); - } } diff --git a/lib/src/private/bdrawer.dart b/lib/src/private/bdrawer.dart index dd72b93..7fd4833 100644 --- a/lib/src/private/bdrawer.dart +++ b/lib/src/private/bdrawer.dart @@ -55,8 +55,11 @@ class BonesDrawer extends Drawer { ), ), ), - onTap: () => Navigator.push(context, - MaterialPageRoute(builder: (context) => item.page())), + onTap: () { + BSettings().pageData.pushCaller(null); + Navigator.push(context, + MaterialPageRoute(builder: (context) => item.page())); + }, ), )) .toList(), diff --git a/lib/src/widget/callback_controller_bones.dart b/lib/src/widget/callback_controller_bones.dart index 8a84fe0..21ca3ad 100644 --- a/lib/src/widget/callback_controller_bones.dart +++ b/lib/src/widget/callback_controller_bones.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; +typedef RedrawCallbackFunction = Function( + RedrawReason reason, String customString); + /// Interface for a callback controller for flutter_bones specific widgets. /// flutter_bones specific widgets: [CheckboxListTileBone], /// [DropDownButtonFormBone], [RaisedButtonBone], [TextFormFieldBone] @@ -8,20 +11,23 @@ abstract class CallbackControllerBones { /// Prepares the rows shown in the list page void buildRows(); - List comboboxTexts( - String customString, CallbackControllerBones controller); + /// Returns the texts of the [ComboboxModel] named [name]. + List comboboxTexts(String name); - List comboboxValues( - String customString, CallbackControllerBones controller); + /// Returns the values of the [ComboboxModel] named [name]. + List comboboxValues(String name); + /// Frees all resources. + void dispose(); + + /// Returns the container for application specific information. ApplicationData getApplicationData(); + /// Returns the [BuildContext] instance of the page. BuildContext getContext(); - FieldModel getModel(String customString, CallbackControllerBones controller); - - String getName(); - + /// Returns the [model] named [name]. + FieldModel getModel(String name); ValueChanged getOnChanged( String customString, CallbackControllerBones controller); @@ -66,14 +72,26 @@ abstract class CallbackControllerBones { String customString, CallbackControllerBones controller, Map row); /// Rebuilds the view of the page. - void redraw(); + /// [reason] and [customString] will be forwarded to the callback function. + void redraw(RedrawReason reason, String customString); /// Returns a standard search button for the list page. Widget searchButton(); /// Starts the change page to edit the record with primary key [id]. - void startChange(int id); + /// [row] contains the db record of [id]. + void startChange(int id, Map row); + + /// Returns the [TextEditingController] instance of a [TextFormField] assigned + /// to a model named [name]. + TextEditingController textController(String name); - /// Returns the field value of field named [fieldName] or null if not found. + /// Returns the field value of [FieldModel] named [fieldName] or null if not found. dynamic valueOf(String fieldName); } + +enum RedrawReason { + custom, + fetchList, + fetchRecord, +} diff --git a/lib/src/widget/checkbox_form_field.dart b/lib/src/widget/checkbox_form_field.dart index 2a54d0e..0cb3257 100644 --- a/lib/src/widget/checkbox_form_field.dart +++ b/lib/src/widget/checkbox_form_field.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import 'page_controller_bones.dart'; class CheckboxFormField extends FormField { CheckboxFormField({ diff --git a/lib/src/widget/edit_form.dart b/lib/src/widget/edit_form.dart index 7dc0f93..428ef51 100644 --- a/lib/src/widget/edit_form.dart +++ b/lib/src/widget/edit_form.dart @@ -17,13 +17,12 @@ class EditForm { @required PageControllerBones pageController, @required BaseConfiguration configuration, int primaryId, + Map initialRow, }) { final padding = configuration.asFloat('form.card.padding', defaultValue: 16.0); + pageController.buildWidgetList(initialRow); final widgets = pageController.getWidgets(); - if (primaryId != null){ - pageController.fetchData(primaryId); - } return Form( key: key, child: Card( diff --git a/lib/src/widget/list_form.dart b/lib/src/widget/list_form.dart index 7d16fbf..90d0e44 100644 --- a/lib/src/widget/list_form.dart +++ b/lib/src/widget/list_form.dart @@ -18,10 +18,8 @@ class ListForm { /// Format of [titles]: first character is the delimiter, e.g. ";Id;Name;" /// This allows to use different delimiters when the title text /// contains characters normally used as delimiters. - static List stringsToTitles(String titles) { + static List stringsToTitles(List titles) { final rc = titles - .substring(1) - .split(titles[0]) .map((String title) => Text(title, style: TextStyle(fontWeight: FontWeight.bold))) .toList(); @@ -45,7 +43,9 @@ class ListForm { TableCallbackController tableCallbackController, String customString, }) { - assert(titles.length == columnNames.length); + if (titles.length != columnNames.length){ + controller.moduleModel.logger.error('titles.length != columnNames.length: ${titles.length}/${columnNames.length}'); + } final titles2 = titles.map((item) => DataColumn(label: item)).toList(); if (showEditIcon) { titles2.insert(0, DataColumn(label: SizedBox(width: 1))); diff --git a/lib/src/widget/page_controller_bones.dart b/lib/src/widget/page_controller_bones.dart index 5d8f6c1..c32bbf4 100644 --- a/lib/src/widget/page_controller_bones.dart +++ b/lib/src/widget/page_controller_bones.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bones/flutter_bones.dart'; import 'package:flutter_bones/src/widget/widget_list.dart'; @@ -14,9 +15,7 @@ class PageControllerBones implements CallbackControllerBones { final ModuleModel moduleModel; String primaryColumn; WidgetList widgetList; - final Function redrawCallback; - bool needsRedraw; - //WidgetList changeWidgets; + final RedrawCallbackFunction redrawCallback; final GlobalKey globalKey; final String pageName; PageModel page; @@ -24,19 +23,20 @@ class PageControllerBones implements CallbackControllerBones { State parent; final BuildContext context; Iterable listRows; + final textControllers = {}; PageControllerBones(this.globalKey, this.parent, this.moduleModel, this.pageName, this.context, this.applicationData, [this.redrawCallback]); + @override void buildRows() { - needsRedraw = true; final persistence = applicationData.persistence; final params = buildSqlParams() ?? {}; persistence.list(module: 'role', params: params).then((list) { if (listRows == null) { listRows = list; - redraw(); + redraw(RedrawReason.fetchList, null); } }, onError: (error) { applicationData.logger.error('cannot retrieve role list: $error'); @@ -51,7 +51,6 @@ class PageControllerBones implements CallbackControllerBones { dynamic value = element.value; DataType dataType = element.dataType; String name = element.name; - String operator; if (element.filterType == FilterType.pattern) { if (value == null || value.isEmpty) { value = '%'; @@ -67,17 +66,33 @@ class PageControllerBones implements CallbackControllerBones { return rc; } + /// Prepares the widgetList: builds the widgets of the page. + /// [initialRow] is null or a map with the field values, e.g. { 'role_name': 'admin' ...} + void buildWidgetList([Map initialRow]) { + widgetList.clear(); + page.fields.forEach((model) { + final value = initialRow == null ? null : initialRow[model.name]; + widgetList.addWidget(model.name, + View(moduleModel.logger).modelToWidget(model, this, value)); + }); + } + @override - List comboboxTexts( - String customString, CallbackControllerBones controller) { + List comboboxTexts(String name) { return []; } @override - List comboboxValues(String customString, CallbackControllerBones controller) { + List comboboxValues(String name) { return []; } + @override + void dispose() { + textControllers.values.forEach((controller) => controller.dispose()); + textControllers.clear(); + } + /// Gets the data from the database using the [primaryId]. fetchData(int primaryId) async { applicationData.persistence @@ -86,8 +101,9 @@ class PageControllerBones implements CallbackControllerBones { page.fields.forEach((model) { model.value = row[model.name]; }); - needsRedraw = true; - redraw(); + + /// navigate to the page "change": + startChange(primaryId, row); }); } @@ -118,18 +134,13 @@ class PageControllerBones implements CallbackControllerBones { } @override - FieldModel getModel(String customString, CallbackControllerBones controller) { - final rc = moduleModel.pageByName(pageName)?.getField(customString); + FieldModel getModel(String name) { + final rc = moduleModel.pageByName(pageName)?.fieldByName(name); return rc; } ModuleModel getModuleModel() => moduleModel; - @override - String getName() { - return null; - } - @override getOnChanged(String customString, CallbackControllerBones controller) { return null; @@ -192,12 +203,17 @@ class PageControllerBones implements CallbackControllerBones { case PageModelType.create: applicationData.persistence .insert(module: moduleModel.name, data: params); + applicationData.popCaller(); Navigator.pop(controller.getContext()); break; case PageModelType.change: applicationData.persistence - .update(module: moduleModel.name, data: params); - Navigator.pop(controller.getContext()); + .update(module: moduleModel.name, data: params) + .then((value) { + applicationData.callerRedraw(RedrawReason.fetchList); + applicationData.popCaller(); + Navigator.pop(controller.getContext()); + }); break; default: moduleModel.logger @@ -207,7 +223,10 @@ class PageControllerBones implements CallbackControllerBones { } }; } else if (customString == 'cancel') { - rc = () => Navigator.pop(controller.getContext()); + rc = () { + applicationData.popCaller(); + Navigator.pop(controller.getContext()); + }; } return rc; } @@ -215,7 +234,7 @@ class PageControllerBones implements CallbackControllerBones { @override getOnSaved(String customString, CallbackControllerBones controller) { final rc = (input) { - FieldModel model = page.getField(customString); + FieldModel model = page.fieldByName(customString); model.value = StringHelper.fromString(input, model.dataType); }; return rc; @@ -255,12 +274,16 @@ class PageControllerBones implements CallbackControllerBones { /// e.g. ModuleModel.parse() is called. /// This method must be called early after the constructor. void initialize() { - widgetList = - WidgetList('${moduleModel.fullName()}.widgets', moduleModel.logger); page = moduleModel.pageByName(pageName); - page.fields.forEach((model) { - widgetList.addWidget( - model.name, View(moduleModel.logger).modelToWidget(model, this)); + widgetList = WidgetList('${page.fullName()}.widgets', moduleModel.logger); + } + + /// Copies the values of [initialRow] into the values of the fields. + void initializeFields(Map initialRow) { + widgetList.widgetMap.keys.forEach((name) { + if (initialRow.containsKey(name)) { + page.fieldByName(name)?.value = initialRow[name]; + } }); } @@ -268,19 +291,18 @@ class PageControllerBones implements CallbackControllerBones { onEditTap(String customString, CallbackControllerBones controller, Map row) { ColumnModel primary = moduleModel.mainTable().primary; final id = row[primary.name]; - controller.startChange(id); + applicationData.persistence + .record(module: moduleModel.name, id: id) + .then((row) => startChange(id, row)); } @override - void redraw() { + void redraw(RedrawReason reason, [String customString]) { if (redrawCallback == null) { moduleModel.logger.error( 'not overridden: fetchListRows() in ${moduleModel.widgetName()}.$pageName'); } else { - if (needsRedraw) { - needsRedraw = false; - redrawCallback(); - } + redrawCallback(reason, customString); } } @@ -292,14 +314,24 @@ class PageControllerBones implements CallbackControllerBones { } @override - void startChange(int id) { + void startChange(int id, Map row) { moduleModel.logger.error( 'missing override of startChange() in ${moduleModel.fullName()}'); } + /// Returns the [TextEditingController] of a [TextFormField] assigned to + /// a model named [name]. + @override + TextEditingController textController(String name) { + if (!textControllers.containsKey(name)) { + textControllers[name] = TextEditingController(); + } + return textControllers[name]; + } + @override dynamic valueOf(String fieldName) { - final rc = page.getField(fieldName)?.value; + final rc = page.fieldByName(fieldName)?.value; return rc; } } diff --git a/lib/src/widget/view.dart b/lib/src/widget/view.dart index 826e61a..2fa2000 100644 --- a/lib/src/widget/view.dart +++ b/lib/src/widget/view.dart @@ -56,23 +56,25 @@ class View { return rc; } - /// Creates a checkbox from the [model]. - Widget checkbox(FieldModel model, CallbackControllerBones controller) { + /// Creates a checkbox from the [model] using the controller with the value [initialValue]. + Widget checkbox(FieldModel model, CallbackControllerBones controller, + [bool initialValue]) { final tristate = model.hasOption('undef'); final rc = toolTip( CheckboxListTileBone(model.name, controller, - value: tristate ? model.value : model.value ?? false, + value: tristate ? initialValue : initialValue ?? false, tristate: tristate, title: Text(model.label), - selected: model.value ?? false), + selected: initialValue ?? false), model); return rc; } /// Creates a combobox via the [controller]. - Widget combobox(FieldModel model, CallbackControllerBones controller) { - final texts = controller.comboboxTexts(model.name, controller); - final values = controller.comboboxValues(model.name, controller) ?? texts; + Widget combobox( + FieldModel model, CallbackControllerBones controller, initialValue) { + final texts = controller.comboboxTexts(model.name); + final values = controller.comboboxValues(model.name) ?? texts; final items = >[]; for (var ix = 0; ix < texts.length; ix++) { items.add(DropdownMenuItem( @@ -80,19 +82,20 @@ class View { value: values[ix], child: Text(texts[ix]))); } - final rc = DropdownButtonFormBone(model.name, controller, items: items); + final rc = DropdownButtonFormBone(model.name, controller, + items: items, value: initialValue); return rc; } - Widget dbReference( - DbReferenceModel model, CallbackControllerBones controller) { + Widget dbReference(DbReferenceModel model, CallbackControllerBones controller, + initialValue) { var rc; if (model.dataType == DataType.bool) { - rc = checkbox(model, controller); + rc = checkbox(model, controller, initialValue); } else if (model.hasOption('combobox')) { - rc = combobox(model, controller); + rc = combobox(model, controller, initialValue); } else { - rc = textField(model, controller); + rc = textField(model, controller, initialValue); } return rc; } @@ -122,12 +125,14 @@ class View { return rc; } - /// Converts a [model] into a [Widget]. - Widget modelToWidget(WidgetModel model, CallbackControllerBones controller) { + /// Converts a [model] into a [Widget] under control of [controller] + /// with the [initialValue]. + Widget modelToWidget(WidgetModel model, CallbackControllerBones controller, + [dynamic initialValue]) { Widget rc; switch (model?.widgetModelType) { case WidgetModelType.textField: - rc = textField(model, controller); + rc = textField(model, controller, initialValue); break; case WidgetModelType.button: rc = button(model, controller); @@ -139,7 +144,7 @@ class View { rc = text(model); break; case WidgetModelType.checkbox: - rc = checkbox(model, controller); + rc = checkbox(model, controller, initialValue); break; case WidgetModelType.combobox: rc = text(model); @@ -151,7 +156,7 @@ class View { rc = section(model); break; case WidgetModelType.dbReference: - rc = dbReference(model, controller); + rc = dbReference(model, controller, initialValue); break; case WidgetModelType.allDbFields: break; @@ -203,11 +208,18 @@ class View { } /// Creates a form text field from the [model]. - Widget textField(FieldModel model, CallbackControllerBones controller) { + Widget textField( + FieldModel model, CallbackControllerBones controller, initialValue) { + final value = + initialValue == null ? null : StringHelper.asString(initialValue); + final textController = controller.textController(model.name); + textController.text = value; var rc = toolTip( TextFormFieldBone( model.name, controller, //validator: model.validator, + controller: textController, + readOnly: model.hasOption('readonly'), decoration: InputDecoration(labelText: model.label), ), model); diff --git a/lib/src/widget/widget_list.dart b/lib/src/widget/widget_list.dart index 1957edd..9fb72af 100644 --- a/lib/src/widget/widget_list.dart +++ b/lib/src/widget/widget_list.dart @@ -58,12 +58,12 @@ class WidgetList { String name; if (element is TextFormFieldBone) { name = element.customString; - final model = page.getField(name, required: true); + final model = page.fieldByName(name, required: true); value = model?.value; dataType = model?.dataType; } else if (element is DropdownButtonFormBone) { name = element.customString; - final model = page.getField(name, required: true); + final model = page.fieldByName(name, required: true); value = model?.value; dataType = model?.dataType; } diff --git a/test/model/db_model_test.dart b/test/model/db_model_test.dart index 17d301f..eca107c 100644 --- a/test/model/db_model_test.dart +++ b/test/model/db_model_test.dart @@ -47,7 +47,7 @@ void main() { expect(userField, isNotNull); expect(userField.widgetName(), 'user_id'); expect(userField.fullName(), equals('user.user_id')); - final userRef = page.getField('user'); + final userRef = page.fieldByName('user'); expect(userRef, isNotNull); expect(userRef.fullName(), equals('create.user')); expect(userRef.widgetName(), equals('user')); diff --git a/test/model/model_test.dart b/test/model/model_test.dart index a4b5c6a..b8400a7 100644 --- a/test/model/model_test.dart +++ b/test/model/model_test.dart @@ -36,7 +36,7 @@ void main() { allDbFields 12 options: ] # change.simpleForm1 '''); - final userField = page.getField('user'); + final userField = page.fieldByName('user'); expect(userField, isNotNull); expect(userField.widgetName(), 'user'); userField.value = 'Hi'; @@ -120,7 +120,7 @@ void main() { module.parse(); var errors = logger.errors; expect(errors.length, equals(0)); - final checkbox = module.pageByName('create').getField('hidden'); + final checkbox = module.pageByName('create').fieldByName('hidden'); expect(checkbox.hasOption('required'), isTrue); checkbox.value = true; expect(checkbox.value, isTrue); @@ -143,7 +143,7 @@ void main() { module.parse(); var errors = logger.errors; expect(errors.length, equals(0)); - final checkbox = module.pageByName('create').getField('hidden'); + final checkbox = module.pageByName('create').fieldByName('hidden'); expect(checkbox, isNotNull); expect(checkbox.dataType, DataType.bool); final dump = module.dump(StringBuffer()).toString(); @@ -186,7 +186,7 @@ void main() { module.parse(); var errors = logger.errors; expect(errors.length, equals(0)); - final combobox = module.pageByName('create').getField('class'); + final combobox = module.pageByName('create').fieldByName('class'); expect(combobox, isNotNull); expect(combobox.dataType, DataType.int); final dump = module.dump(StringBuffer()).toString(); diff --git a/test/widget/widget_test.dart b/test/widget/widget_test.dart index ed13de4..d67b471 100644 --- a/test/widget/widget_test.dart +++ b/test/widget/widget_test.dart @@ -10,6 +10,7 @@ import 'package:flutter/src/foundation/diagnostics.dart'; import 'package:flutter/src/widgets/framework.dart' as x; import 'package:flutter_bones/flutter_bones.dart'; import 'package:flutter_bones/src/widget/widget_helper.dart'; +import 'package:flutter_bones/src/private/bsettings.dart'; import 'package:test/test.dart'; void main() { @@ -26,24 +27,23 @@ void main() { expect(toolTip.child, equals(widget)); }); }); - /* group('ModuleController', () { test('basic', () { - ApplicationData pageData = ApplicationData( + ApplicationData appData = ApplicationData( BaseConfiguration({}, logger), (title) => null, (context) => null, - BSettings.lastInstance.persistence); - final role = RoleCreatePage(pageData); - if (role.lastState == null) { + BSettings.lastInstance.persistence, logger); + final role = RoleCreatePage(appData); + if (appData.lastModuleState == null) { role.createState(); } expect(role, isNotNull); BuildContext context = MyContext(); - role.lastState.build(context); - final widgets = role.lastState.controller.getWidgets(true); + RoleCreatePageState lastInstance = appData.lastModuleState; + lastInstance.build(context); + final widgets = lastInstance.controller.getWidgets(); expect(widgets.length, equals(3)); }); }); - */ } class MyContext extends BuildContext { -- 2.39.5