I'm trying to create settings page from json. But first i'm checking if creating is working on static array:
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
class _SettingsScreenState extends State<SettingsScreen> {
bool lockInBackground = true;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var tilearray = [{'name':'settings no 1'},{'name':'settings no 2'},{'name':'settings no 3'}];
List<SettingsTile> tiles = [];
log('{$tilearray}');
tiles.add( SettingsTile.switchTile(
initialValue: lockInBackground,
onToggle: (bool value) {
setState(() {
lockInBackground = value;
});
},
leading: Icon(Icons.phonelink_lock),
title: Text('settings no 0')));
tilearray.map((item) => log('test{$item.name}'));
tilearray.map((item) => tiles.add( SettingsTile.switchTile(
initialValue: lockInBackground,
onToggle: (bool value) {
setState(() {
lockInBackground = value;
});
},
leading: Icon(Icons.phonelink_lock),
//title: Text(item['name']!))));
title: Text('debug item'))));
log('{$tiles}');
return Scaffold(
appBar: AppBar(title: Text('Settings UI')),
body: SettingsList(
sections: [
SettingsSection(
title: Text('First Section'),
tiles: tiles,
)
]
)
);
}
}
But the result is only one SettingsTile (Setting no 0)...
The comment I add to check if there's a problem with array item, but no. It looks like tilearray is empty.
It is strange that tilearray.map((item) => log('test{$item.name}')); is empty too