Files
checker/lib/base/settings_base_state.dart
2018-12-26 19:43:11 +08:00

68 lines
1.6 KiB
Dart

import 'package:checker/base/base_state.dart';
import 'package:checker/consts.dart';
import 'package:checker/db.dart';
import 'package:checker/strings.dart';
import 'package:flutter/material.dart';
abstract class SettingsBaseState<T extends StatefulWidget> extends BaseState<T> {
SettingsBaseState(SqliteHelper helper, String app) : super(helper, app);
int selectedItem;
@override Widget build(BuildContext context) {
return new Scaffold(appBar: getAppBar(),
body: getScreenContent());
}
@override
Widget getScreenContent() {
getSelectedValue();
List<Widget> widgets = new List();
for (String option in getOptions()) {
widgets.add(getItem(option));
}
return new ListView(children: widgets);
}
List<String> getOptions();
void saveOption(int index);
void getSelectedValue();
@override
List<Widget> getMenuButtons() {
return null;
}
Widget getItem(String option) {
return new Container(
height: 56.0,
child: (new FlatButton(onPressed: () {
final int index = getOptions().indexOf(option);
saveOption(index);
setState(() {
selectedItem = index;
});
},
child: new Row(children: <Widget>[
new Expanded(child: new Text(option)),
getCheckMark(getOptions().indexOf(option))
]))));
}
Widget getCheckMark(int index) {
return index == selectedItem ? new Image.asset(check_png,
width: 28.0,
height: 28.0) : new Image.asset(check_png, color: new Color(0xffffff));
}
@override
String getTitle() {
return StringsLocalization.settings();
}
}