2020-11-25 20:39:54 +01:00
|
|
|
import 'dart:io';
|
|
|
|
|
2021-01-15 19:41:55 +01:00
|
|
|
import 'package:adaptive_theme/adaptive_theme.dart';
|
2020-11-25 20:39:54 +01:00
|
|
|
import 'package:fluffychat/config/setting_keys.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
2021-02-07 08:59:58 +01:00
|
|
|
import '../app_config.dart';
|
2020-11-25 20:39:54 +01:00
|
|
|
import '../components/matrix.dart';
|
|
|
|
|
|
|
|
class SettingsStyle extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_SettingsStyleState createState() => _SettingsStyleState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsStyleState extends State<SettingsStyle> {
|
|
|
|
void setWallpaperAction(BuildContext context) async {
|
|
|
|
final wallpaper = await ImagePicker().getImage(source: ImageSource.gallery);
|
|
|
|
if (wallpaper == null) return;
|
|
|
|
Matrix.of(context).wallpaper = File(wallpaper.path);
|
|
|
|
await Matrix.of(context)
|
|
|
|
.store
|
|
|
|
.setItem(SettingKeys.wallpaper, wallpaper.path);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWallpaperAction(BuildContext context) async {
|
|
|
|
Matrix.of(context).wallpaper = null;
|
|
|
|
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
2021-01-15 19:41:55 +01:00
|
|
|
AdaptiveThemeMode _currentTheme;
|
|
|
|
|
|
|
|
void _switchTheme(AdaptiveThemeMode newTheme, BuildContext context) {
|
|
|
|
switch (newTheme) {
|
|
|
|
case AdaptiveThemeMode.light:
|
|
|
|
AdaptiveTheme.of(context).setLight();
|
|
|
|
break;
|
|
|
|
case AdaptiveThemeMode.dark:
|
|
|
|
AdaptiveTheme.of(context).setDark();
|
|
|
|
break;
|
|
|
|
case AdaptiveThemeMode.system:
|
|
|
|
AdaptiveTheme.of(context).setSystem();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setState(() => _currentTheme = newTheme);
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:39:54 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-01-16 15:33:41 +01:00
|
|
|
_currentTheme ??= AdaptiveTheme.of(context).mode;
|
2020-11-25 20:39:54 +01:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-01-16 14:24:52 +01:00
|
|
|
leading: BackButton(),
|
2020-11-25 20:39:54 +01:00
|
|
|
title: Text(L10n.of(context).changeTheme),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
2021-01-15 19:41:55 +01:00
|
|
|
RadioListTile<AdaptiveThemeMode>(
|
|
|
|
groupValue: _currentTheme,
|
|
|
|
value: AdaptiveThemeMode.system,
|
|
|
|
title: Text(L10n.of(context).systemTheme),
|
|
|
|
onChanged: (t) => _switchTheme(t, context),
|
|
|
|
),
|
|
|
|
RadioListTile<AdaptiveThemeMode>(
|
|
|
|
groupValue: _currentTheme,
|
|
|
|
value: AdaptiveThemeMode.light,
|
|
|
|
title: Text(L10n.of(context).lightTheme),
|
|
|
|
onChanged: (t) => _switchTheme(t, context),
|
|
|
|
),
|
|
|
|
RadioListTile<AdaptiveThemeMode>(
|
|
|
|
groupValue: _currentTheme,
|
|
|
|
value: AdaptiveThemeMode.dark,
|
|
|
|
title: Text(L10n.of(context).darkTheme),
|
|
|
|
onChanged: (t) => _switchTheme(t, context),
|
|
|
|
),
|
2021-02-07 08:59:58 +01:00
|
|
|
Divider(height: 1),
|
2020-11-25 20:39:54 +01:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context).wallpaper,
|
|
|
|
style: TextStyle(
|
2021-02-07 08:59:58 +01:00
|
|
|
color: Theme.of(context).accentColor,
|
2020-11-25 20:39:54 +01:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (Matrix.of(context).wallpaper != null)
|
|
|
|
ListTile(
|
|
|
|
title: Image.file(
|
|
|
|
Matrix.of(context).wallpaper,
|
|
|
|
height: 38,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
|
|
|
trailing: Icon(
|
2020-12-06 10:31:35 +01:00
|
|
|
Icons.delete_forever_outlined,
|
2020-11-25 20:39:54 +01:00
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
onTap: () => deleteWallpaperAction(context),
|
|
|
|
),
|
|
|
|
Builder(builder: (context) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(L10n.of(context).changeWallpaper),
|
2020-12-06 10:31:35 +01:00
|
|
|
trailing: Icon(Icons.wallpaper_outlined),
|
2020-11-25 20:39:54 +01:00
|
|
|
onTap: () => setWallpaperAction(context),
|
|
|
|
);
|
|
|
|
}),
|
2021-02-07 08:59:58 +01:00
|
|
|
Divider(height: 1),
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2021-02-13 14:33:43 +01:00
|
|
|
L10n.of(context).fontSize,
|
2021-02-07 08:59:58 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).accentColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
subtitle: Text('(*${AppConfig.fontSizeFactor})'),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: Theme.of(context).textTheme.bodyText1.fontSize *
|
|
|
|
AppConfig.fontSizeFactor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Slider(
|
|
|
|
min: 0.5,
|
|
|
|
max: 2.5,
|
|
|
|
divisions: 4,
|
|
|
|
value: AppConfig.fontSizeFactor,
|
|
|
|
semanticFormatterCallback: (d) => d.toString(),
|
|
|
|
onChanged: (d) {
|
|
|
|
setState(() => AppConfig.fontSizeFactor = d);
|
|
|
|
Matrix.of(context).store.setItem(
|
|
|
|
SettingKeys.fontSizeFactor,
|
|
|
|
AppConfig.fontSizeFactor.toString(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-11-25 20:39:54 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|