cake_wallet/lib/src/screens/settings/settings.dart

87 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:cake_wallet/src/screens/settings/widgets/settings_version_cell.dart';
import 'package:cake_wallet/view_model/settings/version_list_item.dart';
2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
import 'package:cake_wallet/view_model/settings/link_list_item.dart';
import 'package:cake_wallet/view_model/settings/picker_list_item.dart';
import 'package:cake_wallet/view_model/settings/regular_list_item.dart';
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_link_provider_cell.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_cell_with_arrow.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_picker_cell.dart';
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
import 'package:cake_wallet/src/widgets/standard_list.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/base_page.dart';
class SettingsPage extends BasePage {
2020-07-06 20:09:03 +00:00
SettingsPage(this.settingsViewModel);
2020-01-04 19:31:52 +00:00
2020-07-06 20:09:03 +00:00
final SettingsViewModel settingsViewModel;
2020-01-04 19:31:52 +00:00
@override
2020-07-06 20:09:03 +00:00
String get title => S.current.settings_title;
2020-01-04 19:31:52 +00:00
@override
2020-07-06 20:09:03 +00:00
Widget body(BuildContext context) {
return SectionStandardList(
sectionCount: settingsViewModel.sections.length,
itemCounter: (int sectionIndex) {
if (sectionIndex < settingsViewModel.sections.length) {
return settingsViewModel.sections[sectionIndex].length;
}
return 0;
},
itemBuilder: (_, sectionIndex, itemIndex) {
final item = settingsViewModel.sections[sectionIndex][itemIndex];
if (item is PickerListItem) {
return Observer(builder: (_) {
return SettingsPickerCell<dynamic>(
2020-08-25 16:32:40 +00:00
title: item.title,
selectedItem: item.selectedItem(),
2020-09-10 14:51:59 +00:00
isAlwaysShowScrollThumb: item.isAlwaysShowScrollThumb,
2020-08-25 16:32:40 +00:00
items: item.items,
onItemSelected: (dynamic value) => item.onItemSelected(value),
);
2020-07-06 20:09:03 +00:00
});
}
if (item is SwitcherListItem) {
return Observer(builder: (_) {
return SettingsSwitcherCell(
title: item.title,
value: item.value(),
onValueChange: item.onValueChange);
});
}
if (item is RegularListItem) {
2020-09-10 14:51:59 +00:00
return SettingsCellWithArrow(
title: item.title, handler: item.handler);
2020-07-06 20:09:03 +00:00
}
if (item is LinkListItem) {
return SettingsLinkProviderCell(
title: item.title,
icon: item.icon,
link: item.link,
linkTitle: item.linkTitle);
}
if (item is VersionListItem) {
return Observer(builder: (_) {
return SettingsVersionCell(
2020-09-10 14:51:59 +00:00
title:
S.of(context).version(settingsViewModel.currentVersion));
});
}
2020-07-06 20:09:03 +00:00
return Container();
});
2020-01-04 19:31:52 +00:00
}
}