This repository has been archived on 2020-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
gopher/lib/page/settings.dart

67 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({Key key}) : super(key: key);
@override
_SettingsPageState createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
SharedPreferences prefs;
// The controllers are stored in the state so that,
// when the Widget is rebuild, the cursors do not jump to the beginning of the input field.
TextEditingController fontSizeController = TextEditingController();
_SettingsPageState() {
SharedPreferences.getInstance().then((newPrefs) {
setState(() {
prefs = newPrefs;
});
});
}
@override
Widget build(BuildContext context) {
if (prefs == null)
return Scaffold(
appBar: AppBar(
title: const Text("Settings"),
),
body: const Text("Loading..."),
);
var fontSize = prefs.getDouble('font_size').toString();
if (fontSizeController.text != fontSize)
fontSizeController.text = fontSize;
return Scaffold(
appBar: AppBar(
title: const Text("Settings"),
),
body: Center(
child: ListView(
padding: EdgeInsets.all(8.0),
children: <Widget>[
const Text(
"Font size:",
),
TextField(
enabled: true,
enableInteractiveSelection: true,
keyboardType: TextInputType.number,
controller: fontSizeController,
onSubmitted: (s) {
try {
var fontSize = double.parse(s);
prefs.setDouble('font_size', fontSize);
} on FormatException catch (e) {}
},
),
const Divider(),
],
),
),
);
}
}