Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
275 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_highlight/theme_map.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class CodeModel with ChangeNotifier { | ||
static const _kTheme = 'code-theme'; | ||
static const _kFontSize = 'code-font-size'; | ||
static const _kFontFamily = 'code-font-family'; | ||
|
||
static var themes = themeMap.keys.toList(); | ||
static const fontSizes = [12, 13, 14, 15, 16, 17, 18, 19, 20]; | ||
static const fontFamilies = ['System']; | ||
|
||
String _theme = 'github'; | ||
int _fontSize = 14; | ||
String _fontFamily = 'System'; | ||
|
||
String get theme => _theme; | ||
int get fontSize => _fontSize; | ||
String get fontFamily => _fontFamily; | ||
|
||
init() async { | ||
var prefs = await SharedPreferences.getInstance(); | ||
var vh = prefs.getString(_kTheme); | ||
var vs = prefs.getInt(_kFontSize); | ||
var vf = prefs.getString(_kFontFamily); | ||
|
||
print('read code: $vh, $vs, $vf'); | ||
if (themeMap.keys.contains(vh)) { | ||
_theme = vh; | ||
} | ||
if (fontSizes.contains(vs)) { | ||
_fontSize = vs; | ||
} | ||
if (fontFamilies.contains(vf)) { | ||
_fontFamily = vf; | ||
} | ||
|
||
notifyListeners(); | ||
} | ||
|
||
setTheme(String v) async { | ||
var prefs = await SharedPreferences.getInstance(); | ||
|
||
await prefs.setString(_kTheme, v); | ||
print('write code theme: $v'); | ||
|
||
_theme = v; | ||
notifyListeners(); | ||
} | ||
|
||
setFontSize(int v) async { | ||
var prefs = await SharedPreferences.getInstance(); | ||
|
||
await prefs.setInt(_kFontSize, v); | ||
print('write code font size: $v'); | ||
|
||
_fontSize = v; | ||
notifyListeners(); | ||
} | ||
|
||
setFontFamily(String v) async { | ||
var prefs = await SharedPreferences.getInstance(); | ||
|
||
await prefs.setString(_kFontFamily, v); | ||
print('write code font family: $v'); | ||
|
||
_fontFamily = v; | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_highlight/flutter_highlight.dart'; | ||
import 'package:flutter_highlight/theme_map.dart'; | ||
import 'package:git_touch/models/code.dart'; | ||
import 'package:git_touch/models/theme.dart'; | ||
import 'package:git_touch/scaffolds/simple.dart'; | ||
import 'package:git_touch/utils/utils.dart'; | ||
import 'package:git_touch/widgets/app_bar_title.dart'; | ||
import 'package:git_touch/widgets/table_view.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class CodeSettingsScreen extends StatelessWidget { | ||
final String code; | ||
final String language; | ||
|
||
CodeSettingsScreen(this.code, this.language); | ||
|
||
static Timer _themeDebounce; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
var codeProvider = Provider.of<CodeModel>(context); | ||
|
||
return SimpleScaffold( | ||
title: AppBarTitle('Code theme'), | ||
bodyBuilder: () { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: <Widget>[ | ||
TableView( | ||
items: [ | ||
TableViewItem( | ||
text: Text('Syntax Highlighting'), | ||
rightWidget: Text(codeProvider.theme), | ||
onTap: () { | ||
Provider.of<ThemeModel>(context).showPicker( | ||
context, | ||
children: CodeModel.themes.map((k) => Text(k)).toList(), | ||
initialItem: | ||
CodeModel.themes.indexOf(codeProvider.theme), | ||
onSelectedItemChanged: (int value) { | ||
if (_themeDebounce?.isActive ?? false) | ||
_themeDebounce.cancel(); | ||
_themeDebounce = | ||
Timer(const Duration(milliseconds: 500), () { | ||
Provider.of<CodeModel>(context) | ||
.setTheme(CodeModel.themes[value]); | ||
}); | ||
}, | ||
); | ||
}), | ||
TableViewItem( | ||
text: Text('Font Size'), | ||
rightWidget: Text(codeProvider.fontSize.toString()), | ||
onTap: () { | ||
Provider.of<ThemeModel>(context).showPicker( | ||
context, | ||
children: CodeModel.fontSizes | ||
.map((k) => Text(k.toString())) | ||
.toList(), | ||
initialItem: | ||
CodeModel.fontSizes.indexOf(codeProvider.fontSize), | ||
onSelectedItemChanged: (int value) { | ||
if (_themeDebounce?.isActive ?? false) | ||
_themeDebounce.cancel(); | ||
_themeDebounce = | ||
Timer(const Duration(milliseconds: 500), () { | ||
Provider.of<CodeModel>(context) | ||
.setFontSize(CodeModel.fontSizes[value]); | ||
}); | ||
}, | ||
); | ||
}, | ||
), | ||
TableViewItem( | ||
text: Text('Font Family'), | ||
rightWidget: Text(codeProvider.fontFamily.toString()), | ||
onTap: () { | ||
// TODO: | ||
}, | ||
), | ||
], | ||
), | ||
SingleChildScrollView( | ||
scrollDirection: Axis.horizontal, | ||
child: HighlightView( | ||
code, | ||
language: language, | ||
theme: themeMap[codeProvider.theme], | ||
textStyle: TextStyle( | ||
fontSize: codeProvider.fontSize.toDouble(), | ||
fontFamily: monospaceFont, | ||
), | ||
padding: const EdgeInsets.all(10), | ||
), | ||
) | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.