weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
super.initState();
}
- void store() {
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Benchmarks',
'sql': 'insert',
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
BenchmarkMeta.instance.pageByName('create')!,
BenchmarkMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndDelete(),
+ onPressed: () => onVerifyAndDelete(),
child: Text(i18n.tr('Delete'))),
weight: 8,
gapAbove: 2 * padding),
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void delete() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onDelete() {
final parameters = <String, dynamic>{
'module': 'Benchmarks',
'sql': 'delete',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
});
}
- void verifyAndDelete() {
+ void onVerifyAndDelete() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- delete();
+ onDelete();
}
}
}
BenchmarkMeta.instance.pageByName('delete')!,
BenchmarkMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void store() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Benchmarks',
'sql': 'update',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
_fieldData.toMap(parameters);
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
+ requestRecord();
attendedPage!.pageStates.dbDataState.clear();
setState(() => 1);
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
BenchmarkMeta.instance.pageByName('edit')!,
BenchmarkMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
import '../../base/defines.dart';
import '../../base/helper.dart';
import '../../base/i18n.dart';
-import '../../base/validators.dart';
import '../../services/global_widget.dart';
import '../../setting/global_data.dart';
import '../../widget/attended_page.dart';
import '../../widget/widget_form.dart';
import '../../persistence/persistence.dart';
-import '../../common/benchmark_actions.dart';
import 'list_benchmark_page.dart';
final i18n = I18N();
final GlobalKey<FormState> _formKey =
GlobalKey<FormState>(debugLabel: 'CreateBenchmark');
final textController = TextEditingController();
- final countController = TextEditingController();
- final resultController = TextEditingController();
ListBenchmarkCustom();
@override
Widget build(BuildContext context) {
onDone: () => setState(() => 1),
routeEdit: '/Benchmarks/edit',
context: context);
- rc = buildFrame(rows: rows);
+ rc = buildFrame(
+ totalCount: snapshot.data?.count ?? rows.length, rows: rows);
} else if (snapshot.hasError) {
rc = Text('Backend problem: ${snapshot.error}');
} else {
return rc;
}
- Widget buildFrame({required JsonList rows}) {
+ Widget buildFrame({required JsonList rows, required int totalCount}) {
final padding = GlobalThemeData.padding;
final formItems = <FormItem>[
FormItem(
weight: 12,
gapAbove: padding),
];
- final belowForm = Padding(
- padding: EdgeInsets.symmetric(vertical: padding, horizontal: padding),
- child: Column(children: [
- SizedBox(
- height: padding,
- ),
- Row(children: [
- Expanded(
- child: TextFormField(
- controller: countController,
- decoration: InputDecoration(labelText: i18n.tr('Count')),
- onSaved: (value) => _fieldData.count = value ?? '',
- validator: (input) => isNat(input),
- )),
- SizedBox(width: padding),
- Expanded(
- child: ElevatedButton(
- onPressed: () => createNew(),
- child: Text(i18n.tr('Create new elements')))),
- SizedBox(width: padding),
- Expanded(
- child: ElevatedButton(
- onPressed: () => readItems(),
- child: Text(i18n.tr('Read existing elements')))),
- ]),
- SizedBox(height: padding),
- Row(children: [
- Expanded(
- child: TextFormField(
- controller: resultController,
- decoration: InputDecoration(labelText: i18n.tr('Message')),
- readOnly: true,
- ))
- ])
- ]));
final form = Form(
key: _formKey,
- child: Column(children: [
- Card(
- color: GlobalThemeData.formBackgroundColor,
- elevation: GlobalThemeData.formElevation,
- margin:
- EdgeInsets.symmetric(vertical: padding, horizontal: padding),
- child: Padding(
- padding: EdgeInsets.symmetric(
- vertical: padding, horizontal: padding),
- child: WidgetForm.flexibleGrid(formItems,
- screenWidth: attendedPage!.pageStates.screenWidth,
- padding: padding))),
- belowForm,
- ]));
+ child: Card(
+ color: GlobalThemeData.formBackgroundColor,
+ elevation: GlobalThemeData.formElevation,
+ margin:
+ EdgeInsets.symmetric(vertical: padding, horizontal: padding),
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ vertical: padding, horizontal: padding),
+ child: WidgetForm.flexibleGrid(formItems,
+ screenWidth: attendedPage!.pageStates.screenWidth,
+ padding: padding))));
final table = DataTable(
columns: <DataColumn>[
DataColumn(
],
rows: rows as List<DataRow>,
);
- Widget? tabBar =
- attendedPage!.buildChipBar(onTap: (offset) => setState(() => offset));
+ Widget? tabBar = attendedPage!.buildChipBar(
+ totalCount: totalCount,
+ offset: _fieldData.theOffset,
+ pageSize: _fieldData.thePageSize,
+ onTap: (offset) {
+ _fieldData.theOffset = offset;
+ requestRecords();
+ setState(() => 1);
+ });
final frameWidget = ListView(children: [
form,
if (tabBar != null) tabBar,
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
- 'module': 'Benchmarks',
- 'sql': 'list',
- 'offset': _fieldData.theOffset,
- 'size': _fieldData.thePageSize,
- ':text': asPattern(_fieldData.text),
- });
- }
-
- void createNew() {
- final benchMark = BenchmarkActions(globalData);
- benchMark
- .createMultiple(int.tryParse(countController.text) ?? 1)
- .then((message) => setState(() => resultController.text = message));
+ requestRecords();
}
@override
helperDummyUsage(DataType.string);
globalWidgetDummyUsage();
textController.dispose();
- countController.dispose();
- resultController.dispose();
super.dispose();
}
super.initState();
}
- void readItems() {
- final benchMark = BenchmarkActions(globalData);
- // resultController.text = benchMark.createMultiple(
- // int.tryParse(_fieldData.count) ?? 1);
- setState(() => 1);
- }
+ void requestRecords() =>
+ _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
+ 'module': 'Benchmarks',
+ 'sql': 'list',
+ 'offset': _fieldData.theOffset,
+ 'size': _fieldData.thePageSize,
+ ':text': asPattern(_fieldData.text),
+ });
void search() {
attendedPage!.pageStates.dbDataState.clear();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
+ requestRecords();
setState(() => 1);
}
}
int thePageSize = 10;
int theOffset = 0;
String text = '';
- String count = '';
}
BenchmarkMeta.instance.pageByName('list')!,
BenchmarkMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
super.initState();
}
- void store() {
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Roles',
'sql': 'insert',
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
RoleMeta.instance.pageByName('create')!,
RoleMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void store() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Roles',
'sql': 'update',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
_fieldData.toMap(parameters);
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
+ requestRecord();
attendedPage!.pageStates.dbDataState.clear();
setState(() => 1);
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
RoleMeta.instance.pageByName('edit')!,
RoleMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
onDone: () => setState(() => 1),
routeEdit: '/Roles/edit',
context: context);
- rc = buildFrame(rows: rows);
+ rc = buildFrame(
+ totalCount: snapshot.data?.count ?? rows.length, rows: rows);
} else if (snapshot.hasError) {
rc = Text('Backend problem: ${snapshot.error}');
} else {
return rc;
}
- Widget buildFrame({required JsonList rows}) {
+ Widget buildFrame({required JsonList rows, required int totalCount}) {
final padding = GlobalThemeData.padding;
final formItems = <FormItem>[
FormItem(
],
rows: rows as List<DataRow>,
);
- Widget? tabBar =
- attendedPage!.buildChipBar(onTap: (offset) => setState(() => offset));
+ Widget? tabBar = attendedPage!.buildChipBar(
+ totalCount: totalCount,
+ offset: _fieldData.theOffset,
+ pageSize: _fieldData.thePageSize,
+ onTap: (offset) {
+ _fieldData.theOffset = offset;
+ requestRecords();
+ });
final frameWidget = ListView(children: [
form,
if (tabBar != null) tabBar,
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
- 'module': 'Roles',
- 'sql': 'list',
- 'offset': _fieldData.theOffset,
- 'size': _fieldData.thePageSize,
- ':text': _fieldData.text,
- });
+ requestRecords();
}
@override
super.initState();
}
+ void requestRecords() =>
+ _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
+ 'module': 'Roles',
+ 'sql': 'list',
+ 'offset': _fieldData.theOffset,
+ 'size': _fieldData.thePageSize,
+ ':text': _fieldData.text,
+ });
+
void search() {
attendedPage!.pageStates.dbDataState.clear();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
+ requestRecords();
setState(() => 1);
}
}
RoleMeta.instance.pageByName('list')!,
RoleMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
super.initState();
}
- void store() {
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Structures',
'sql': 'insert',
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
StructureMeta.instance.pageByName('create')!,
StructureMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndDelete(),
+ onPressed: () => onVerifyAndDelete(),
child: Text(i18n.tr('Delete'))),
weight: 8,
gapAbove: 2 * padding),
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void delete() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onDelete() {
final parameters = <String, dynamic>{
'module': 'Structures',
'sql': 'delete',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
});
}
- void verifyAndDelete() {
+ void onVerifyAndDelete() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- delete();
+ onDelete();
}
}
}
StructureMeta.instance.pageByName('delete')!,
StructureMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void store() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Structures',
'sql': 'update',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
_fieldData.toMap(parameters);
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
+ requestRecord();
attendedPage!.pageStates.dbDataState.clear();
setState(() => 1);
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
StructureMeta.instance.pageByName('edit')!,
StructureMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
onDone: () => setState(() => 1),
routeEdit: '/Structures/edit',
context: context);
- rc = buildFrame(rows: rows);
+ rc = buildFrame(
+ totalCount: snapshot.data?.count ?? rows.length, rows: rows);
} else if (snapshot.hasError) {
rc = Text('Backend problem: ${snapshot.error}');
} else {
return rc;
}
- Widget buildFrame({required JsonList rows}) {
+ Widget buildFrame({required JsonList rows, required int totalCount}) {
final padding = GlobalThemeData.padding;
final formItems = <FormItem>[
FormItem(
],
rows: rows as List<DataRow>,
);
- Widget? tabBar =
- attendedPage!.buildChipBar(onTap: (offset) => setState(() => offset));
+ Widget? tabBar = attendedPage!.buildChipBar(
+ totalCount: totalCount,
+ offset: _fieldData.theOffset,
+ pageSize: _fieldData.thePageSize,
+ onTap: (offset) {
+ _fieldData.theOffset = offset;
+ requestRecords();
+ });
final frameWidget = ListView(children: [
form,
if (tabBar != null) tabBar,
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
- 'module': 'Structures',
- 'sql': 'list',
- 'offset': _fieldData.theOffset,
- 'size': _fieldData.thePageSize,
- ':text': _fieldData.text,
- });
+ requestRecords();
}
@override
super.initState();
}
+ void requestRecords() =>
+ _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
+ 'module': 'Structures',
+ 'sql': 'list',
+ 'offset': _fieldData.theOffset,
+ 'size': _fieldData.thePageSize,
+ ':text': _fieldData.text,
+ });
+
void search() {
attendedPage!.pageStates.dbDataState.clear();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
+ requestRecords();
setState(() => 1);
}
}
StructureMeta.instance.pageByName('list')!,
StructureMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
super.initState();
}
- void store() {
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Users',
'sql': 'insert',
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
UserMeta.instance.pageByName('create')!,
UserMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndDelete(),
+ onPressed: () => onVerifyAndDelete(),
child: Text(i18n.tr('Delete'))),
weight: 8,
gapAbove: 2 * padding),
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void delete() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onDelete() {
final parameters = <String, dynamic>{
'module': 'Users',
'sql': 'delete',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
});
}
- void verifyAndDelete() {
+ void onVerifyAndDelete() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- delete();
+ onDelete();
}
}
}
UserMeta.instance.pageByName('delete')!,
UserMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
drawer: globalData.drawerBuilder(context),
body: SafeArea(
child: FutureBuilder<DbData>(
- future: _futureDbData,
- builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null) {
- rc =
- Text('backend problem: ${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: ${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
- return rc;
- },
- )));
+ future: _futureDbData,
+ builder: (context, snapshot) {
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
+ return rc;
+ })));
return rc;
}
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndStore(), child: Text(i18n.tr('Save'))),
+ onPressed: () => onVerifyAndStore(),
+ child: Text(i18n.tr('Save'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}
@override
super.initState();
}
- void store() {
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+ void onStore() {
final parameters = <String, dynamic>{
'module': 'Users',
'sql': 'update',
+ ':id': primaryKey
};
- parameters[':id'] = primaryKey;
_fieldData.toMap(parameters);
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
+ requestRecord();
attendedPage!.pageStates.dbDataState.clear();
setState(() => 1);
});
}
- void verifyAndStore() {
+ void onVerifyAndStore() {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
- store();
+ onStore();
}
}
}
UserMeta.instance.pageByName('edit')!,
UserMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
onDone: () => setState(() => 1),
routeEdit: '/Users/edit',
context: context);
- rc = buildFrame(rows: rows);
+ rc = buildFrame(
+ totalCount: snapshot.data?.count ?? rows.length, rows: rows);
} else if (snapshot.hasError) {
rc = Text('Backend problem: ${snapshot.error}');
} else {
return rc;
}
- Widget buildFrame({required JsonList rows}) {
+ Widget buildFrame({required JsonList rows, required int totalCount}) {
final padding = GlobalThemeData.padding;
comboRolesFromBackend(
attendedPage: attendedPage!, onDone: () => setState(() => 1));
],
rows: rows as List<DataRow>,
);
- Widget? tabBar =
- attendedPage!.buildChipBar(onTap: (offset) => setState(() => offset));
+ Widget? tabBar = attendedPage!.buildChipBar(
+ totalCount: totalCount,
+ offset: _fieldData.theOffset,
+ pageSize: _fieldData.thePageSize,
+ onTap: (offset) {
+ _fieldData.theOffset = offset;
+ requestRecords();
+ });
final frameWidget = ListView(children: [
form,
if (tabBar != null) tabBar,
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
- 'module': 'Users',
- 'sql': 'list',
- 'offset': _fieldData.theOffset,
- 'size': _fieldData.thePageSize,
- ':text': asPattern(_fieldData.text),
- ':role': _fieldData.role.toString(),
- });
+ requestRecords();
}
@override
super.initState();
}
+ void requestRecords() =>
+ _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
+ 'module': 'Users',
+ 'sql': 'list',
+ 'offset': _fieldData.theOffset,
+ 'size': _fieldData.thePageSize,
+ ':text': asPattern(_fieldData.text),
+ ':role': _fieldData.role.toString(),
+ });
+
void search() {
attendedPage!.pageStates.dbDataState.clear();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
+ requestRecords();
setState(() => 1);
}
}
UserMeta.instance.pageByName('list')!,
UserMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload) {
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
if (afterReload == null) {
- setState(() => 1);
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
}
void goto(BuildContext context, String route,
{bool popIfPossible = true, bool registerWithParent = false}) {
final ix = route.indexOf(';');
- if (ix > 0) {
- route = route.substring(0, ix);
- }
+ final route2 = ix > 0 ? route.substring(0, ix) : route;
if (popIfPossible &&
stack.length >= 2 &&
- stack[stack.length - 2].route == route) {
+ stack[stack.length - 2].route == route2) {
pop(context);
} else {
/// Note: constructor of AttendedPage calls supplyTopOfStack()
/// to set NavigatorStackEntry.attendedPage.
stack.add(NavigatorStackEntry(
- route: route, registerWithParent: registerWithParent));
+ route: route2, registerWithParent: registerWithParent));
Navigator.pushNamed(context, route);
}
}
globalData!.logger
.error('informAboutChanges(): parent ${route!} not found');
} else {
- parent.noticeChange();
+ // parent.noticeChange();
+ parent.reload(rebuild: true);
}
}
}
if (last.registerWithParent && stack.length >= 2) {
stack[stack.length - 2]
.attendedPage
- ?.addListener(() => attendedPage.reload());
+ ?.addListener(() => attendedPage.reload(rebuild: true));
}
} else {
globalData!.logger.error(
final StatefulWidget statefulWidget;
final State<StatefulWidget> state;
final PageStates pageStates;
- final void Function(Function? afterReload)? reloadFunction;
+ final void Function(Function? afterReload, bool rebuild)? reloadFunction;
AttendedPage(
this.statefulWidget,
this.state,
///
/// If [afterReload] is not null this function is used as parameter of
/// setState().
- void reload({Function? afterReload}) {
- reloadFunction!(afterReload);
+ void reload({Function? afterReload, bool rebuild = false}) {
+ reloadFunction!(afterReload, rebuild);
}
/// Creates a chip bar: a row of ChoiceChip instances (special buttons).
///
/// That chips allow to change the page of the db result.
///
+ /// [totalCount]: the number of records matching the filters.
+ ///
+ /// [offset]: the offset of the result in the result set.
+ ///
+ /// [pageSize]: the page size defining the maximal entries in the result set.
+ ///
/// [onTap]: a function which is called if another chip is selected.
- Widget? buildChipBar({required Function(int offset) onTap}) {
- final dbData = pageStates.dbDataState.dataOf('rows');
- final pageSize = dbData?.pageSize ?? 10;
- //pageSize = 10;
- final totalCount = dbData?.count ?? pageSize;
- //totalCount = 1;
- final offset = dbData?.offset ?? 0;
- // offset = 30;
+ Widget? buildChipBar(
+ {required int totalCount,
+ required int offset,
+ required int pageSize,
+ required Function(int offset) onTap}) {
final pageCount = (totalCount + pageSize - 1) ~/ pageSize;
final currentPage = 1 + offset ~/ pageSize;
int currentIndex;
return rc ?? <DataRow>[];
}
+ /// Informs the listeners of [ChangeNotifier] about a change.
void noticeChange() {
notifyListeners();
}
+ /// Informs a parent about changes.
+ ///
+ /// See [globalData.navigatorStack.informAboutChanges()]
void informAboutChanges({String? route}) {
globalData.navigatorStack.informAboutChanges(route);
}
/// Loads a record from the backend.
///
- /// [name]: a unique name over all backend data requests.
- ///
- /// [reload]: a function calling setState().
+ /// [onSuccess]: this function must convert the Json format to the native
+ /// object and must return the (complex) widget displaying the record.
///
- /// [onDone]: a function storing the record fetched from the backend.
- ///
- /// [parameters]: a map specifying the request.
- /// Example: { 'module': 'Roles', 'sql': 'byId', ':id': primaryKey}.///
- void loadRecord(
- {required String name,
- required void Function() reload,
- required void Function(JsonMap) onDone,
- required Map<String, dynamic> parameters}) {
- if (!pageStates.dbDataState.hasEntry(name)) {
- pageStates.dbDataState.addRequest(name).then((_) => globalData
- .restPersistence!
- .query(what: 'query', data: parameters)
- .then((value) {
- pageStates.dbDataState
- .storeDbResult(name, value)
- .then((_) => reload());
- }));
- } else if (pageStates.dbDataState.dataOf('record') != null) {
- final dbData = pageStates.dbDataState.dataOf('record');
- if (dbData != null && dbData.singleRecord != null) {
- onDone(dbData.singleRecord!);
+ /// Returns: An error text on network errors, a progress indicator while data
+ /// is not available or the widget displaying the record on success.
+ Widget loadRecord(
+ AsyncSnapshot snapshot, Widget Function(JsonMap record) onSuccess) {
+ Widget rc;
+ if (snapshot.connectionState != ConnectionState.done) {
+ rc = const CircularProgressIndicator();
+ } else {
+ if (snapshot.hasData) {
+ final dbData = snapshot.data!;
+ final record = dbData.singleRecord;
+ if (record == null) {
+ rc = Text('backend problem: ${dbData.message ?? '<unknown>'}');
+ }
+ rc = onSuccess(record as JsonMap);
+ } else if (snapshot.hasError) {
+ rc = Text('Backend problem: ${snapshot.error}');
+ } else {
+ rc = const CircularProgressIndicator();
}
}
+ return rc;
}
/// Validates the text [value] of the [textAttended].
child: FutureBuilder<DbData>(
future: _futureDbData,
builder: (context, snapshot) {
- Widget rc;
- if (snapshot.connectionState != ConnectionState.done) {
- rc = const CircularProgressIndicator();
- } else {
- if (snapshot.hasData) {
- final dbData = snapshot.data!;
- final record = dbData.singleRecord;
- if (record == null){
- rc = Text('backend problem: \${dbData.message ?? '<unknown>'}');
- }
- _fieldData.fromMap(record as JsonMap);
- rc = buildFrame();
- } else if (snapshot.hasError) {
- rc = Text('Backend problem: \${snapshot.error}');
- } else {
- rc = const CircularProgressIndicator();
- }
- }
+ final rc = attendedPage!.loadRecord(snapshot, (record) {
+ _fieldData.fromMap(record);
+ return buildFrame();
+ });
return rc;
- },
- )));''';
+ })));''';
static final templateBodySimple = '''SafeArea(
child: buildFrame()));''';
static final templateDidChangeDependencies = '''
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(
- what: 'query',
- data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+ requestRecord();
}''';
static final templatePage = '''
UserMeta.instance.pageByName('edit')!,
UserMeta.instance,
pageStates,
- (afterReload) => rc.reload(afterReload));
+ (afterReload, rebuild) =>
+ rc.reload(afterReload: afterReload, rebuild: rebuild));
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
/// Renders the widget tree again.
- void reload(Function? afterReload){
- if (afterReload == null){
- setState(() => 1);
+ ///
+ /// [afterReload] is a function used as parameter of setState().
+ ///
+ /// If [rebuild] is true the state has been changed and didChangeDependencies()
+ /// will be called.
+ void reload({Function? afterReload, bool rebuild = false}) {
+ if (afterReload == null) {
+ if (rebuild) {
+ setState(() => didChangeDependencies());
+ } else {
+ setState(() => 1);
+ }
} else {
- setState(() => afterReload());
+ setState(() {
+ afterReload();
+ if (rebuild) {
+ didChangeDependencies();
+ }
+ });
}
}
-}
-''';
+}''';
static final templateGlobalComboBox = ''' comboRolesFromBackend(
attendedPage: attendedPage!, onDone: () => setState(() => 1));
onDone: () => setState(() => 1),
route#EDIT1: '/Users/#EDIT2',
context: context);
- rc = buildFrame(rows: rows);
+ rc = buildFrame(totalCount: snapshot.data?.count ?? rows.length,
+ rows: rows);
} else if (snapshot.hasError) {
rc = Text('Backend problem: \${snapshot.error}');
} else {
return rc;
}
- Widget buildFrame({required JsonList rows}){
+ Widget buildFrame({required JsonList rows, required int totalCount}){
final padding = GlobalThemeData.padding;
#INIT_COMBOS final formItems = <FormItem>[
#FORM_ITEMS FormItem(
#TABLE_HEADER ],
rows: rows as List<DataRow>,
);
- Widget? tabBar =
- attendedPage!.buildChipBar(onTap: (offset) => setState(() => offset));
+ Widget? tabBar = attendedPage!.buildChipBar(
+ totalCount: totalCount,
+ offset: _fieldData.theOffset,
+ pageSize: _fieldData.thePageSize,
+ onTap: (offset) {
+ _fieldData.theOffset = offset;
+ requestRecords();
+ setState(() => 1);
+ });
final frameWidget = ListView(children: [
form,
if (tabBar != null) tabBar,
@override
void didChangeDependencies() {
super.didChangeDependencies();
- _futureDbData = globalData.restPersistence!.query(what: 'query', data: {
- 'module': 'Users',
- 'sql': 'list',
- 'offset': _fieldData.theOffset,
- 'size': _fieldData.thePageSize,
-#PARAM_DEF });
+ requestRecords();
}
@override
super.initState();
}
+ void requestRecords() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query', data: {
+ 'module': 'Users',
+ 'sql': 'list',
+ 'offset': _fieldData.theOffset,
+ 'size': _fieldData.thePageSize,
+#PARAM_DEF });
+
void search() {
attendedPage!.pageStates.dbDataState.clear();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
+ requestRecords();
setState(() => 1);
}
}
super.initState();
}
- void #ACTION1() {
+#REQ_RECORD void #ACTION1() {
final parameters = <String, dynamic>{
'module': 'Users',
'sql': '#SQL_TYPE',
- };
-#SET_PRIMARY#CALL_TO_MAP globalData.restPersistence!
+#SET_PRIMARY };
+#CALL_TO_MAP globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {#STORAGE_DONE});
}
#DEF_FIELD
#FROM_MAP#TO_MAP}
''';
+ static final templateRequestRecord = '''
+ void requestRecord() => _futureDbData = globalData.restPersistence!.query(
+ what: 'query',
+ data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey});
+
+''';
+
static final templateStorageDoneCreate = '''
if (answer.startsWith('id:')) {
''';
static final templateStorageDoneEdit = '''
+ requestRecord();
attendedPage!.pageStates.dbDataState.clear();
setState(() => 1);
''';
String createRecordCustomized(PageMetaData page) {
var hasPrimary = false;
page.pageType == PageType.edit || page.pageType == PageType.delete;
- var action1 = 'store';
- var action2 = 'verifyAndStore';
+ var action1 = 'onStore';
+ var action2 = 'onVerifyAndStore';
var storageDone = '';
var buttonText = 'Save';
var sqlType = '';
- var setPrimary = '';
+ var setPrimary = " ':id': primaryKey\n";
var callToMap = '';
var body = templateBodyLoadData;
var didChangeDependencies = templateDidChangeDependencies;
var definitionFuture = ' late Future<DbData> _futureDbData;';
var importPersistence = "import '../../persistence/persistence.dart';\n";
+ var informAboutChanges = ' attendedPage!.informAboutChanges();';
+ var requestRecord = templateRequestRecord;
page.pageType == PageType.edit
? 'update'
: (page.pageType == PageType.delete ? 'delete' : 'insert');
storageDone = templateStorageDoneCreate.replaceFirst(
'#MODULE', page.module.moduleName);
body = templateBodySimple;
- didChangeDependencies = '';
- definitionFuture = '';
- importPersistence = '';
+ didChangeDependencies = definitionFuture = importPersistence
+ = informAboutChanges = setPrimary = requestRecord = '';
break;
case PageType.edit:
callToMap = ' _fieldData.toMap(parameters);\n';
- setPrimary = " parameters[':id'] = primaryKey;\n";
sqlType = 'update';
storageDone = templateStorageDoneEdit;
hasPrimary = true;
break;
case PageType.delete:
- setPrimary = " parameters[':id'] = primaryKey;\n";
sqlType = 'delete';
buttonText = 'Delete';
- action1 = 'delete';
- action2 = 'verifyAndDelete';
+ action1 = 'onDelete';
+ action2 = 'onVerifyAndDelete';
storageDone = templateStorageDoneDelete.replaceFirst(
'#MODULE', page.module.moduleName);
hasPrimary = true;
break;
}
var rc = replaceVariables(templateRecordCustom, page)
+ .replaceFirst('#REQ_RECORD', requestRecord)
.replaceFirst('#DIDCHANGE', didChangeDependencies)
.replaceFirst('#DEF_CONTROLLER', buildDefinitionControllers(page))
.replaceFirst('#INIT_COMBO', buildInitializeComboBoxes(page))
.replaceFirst('#TO_MAP', buildToMap(page))
.replaceFirst('#FROM_MAP', buildFromMap(page))
.replaceFirst('#DEF_FUTURE', definitionFuture)
+ .replaceFirst('#INFORM', informAboutChanges)
.replaceFirst('#IMP_PERSISTENCE', importPersistence);
return rc;
}
sql2 = sql;
} else {
final ix = sql.lastIndexOf(';');
- if (ix > 0) {
- sql2 = sql.substring(0, ix) +
- ' limit ${parameters["offset"]},${parameters["size"]};';
- } else {
- sql2 = sql + ' limit ${parameters["offset"]},${parameters["size"]};';
- }
+ final limit = ' limit ${parameters["offset"]},${parameters["size"]};';
+ sql2 = (ix > 0 ? sql.substring(0, ix) : sql) + limit;
final fromPart = 'FROM ${module.toLowerCase()} t0';
final ix2 = sql.indexOf(fromPart);
if (ix2 > 0) {
: positionalParameters
.skip(positionalParameters.length - countParams)
.toList();
- prefix =
- '#${await db!.readOneInt(sqlCount, params: positionalParameters2)}';
+ prefix = '#' +
+ (await db!.readOneInt(sqlCount, params: positionalParameters2))
+ .toString();
}
+ logger.log('(offset, pagesize): ($limit)', LEVEL_DETAIL);
}
final records = await db!.readAll(sql2, params: positionalParameters);
rc = records == null