1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-21 20:44:33 +01:00
git-touch-android-ios-app/lib/screens/code_theme.dart

162 lines
5.2 KiB
Dart
Raw Normal View History

2019-09-15 11:36:09 +02:00
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';
2019-09-29 09:02:06 +02:00
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/single.dart';
2019-10-02 09:39:47 +02:00
import 'package:git_touch/utils/utils.dart';
2019-09-15 11:36:09 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-29 09:02:06 +02:00
import 'package:git_touch/widgets/table_view.dart';
2019-09-15 11:36:09 +02:00
import 'package:provider/provider.dart';
2020-01-12 10:13:48 +01:00
final codeThemeRouter = RouterScreen(
'/choose-code-theme',
(context, parameters) {
return CodeThemeScreen();
},
);
2019-09-28 18:25:14 +02:00
class CodeThemeScreen extends StatelessWidget {
2020-01-12 10:13:48 +01:00
String _getCode(bool isDark) => '''// ${isDark ? 'Dark' : 'Light'} Mode
import 'package:flutter/material.dart';
2019-09-15 11:36:09 +02:00
2020-01-12 10:13:48 +01:00
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Hello World'),
),
),
);
}
}
''';
2019-09-15 11:36:09 +02:00
@override
Widget build(BuildContext context) {
var codeProvider = Provider.of<CodeModel>(context);
2020-01-12 10:13:48 +01:00
var theme = Provider.of<ThemeModel>(context);
2019-09-15 11:36:09 +02:00
2019-09-25 11:06:36 +02:00
return SingleScaffold(
2019-09-15 11:36:09 +02:00
title: AppBarTitle('Code theme'),
2019-09-25 11:06:36 +02:00
body: Column(
2019-09-25 08:24:20 +02:00
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2020-01-12 10:13:48 +01:00
CommonStyle.verticalGap,
2019-09-29 09:02:06 +02:00
TableView(
2020-01-12 10:13:48 +01:00
headerText: 'FONT STYLE',
2019-09-25 08:24:20 +02:00
items: [
2019-09-29 09:02:06 +02:00
TableViewItem(
text: Text('Font Size'),
rightWidget: Text(codeProvider.fontSize.toString()),
onTap: () {
2020-01-12 10:13:48 +01:00
theme.showPicker(
2019-09-29 09:02:06 +02:00
context,
PickerGroupItem(
value: codeProvider.fontSize.toString(),
items: CodeModel.fontSizes
.map((v) =>
PickerItem(v.toString(), text: v.toString()))
.toList(),
onChange: (value) {
2020-01-12 10:13:48 +01:00
codeProvider.setFontSize(int.tryParse(value) ?? 16);
2019-09-29 09:02:06 +02:00
},
),
);
2019-09-25 08:24:20 +02:00
},
),
2019-09-29 09:02:06 +02:00
TableViewItem(
text: Text('Font Family'),
rightWidget: Text(codeProvider.fontFamily),
onTap: () {
2020-01-12 10:13:48 +01:00
theme.showPicker(
2019-09-29 09:02:06 +02:00
context,
PickerGroupItem(
value: codeProvider.fontFamily,
items: CodeModel.fontFamilies
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (String value) {
2020-01-12 10:13:48 +01:00
codeProvider.setFontFamily(value);
2019-09-29 09:02:06 +02:00
},
),
);
2019-09-25 08:24:20 +02:00
},
2019-09-15 11:36:09 +02:00
),
2019-09-25 08:24:20 +02:00
],
),
2020-01-12 10:13:48 +01:00
CommonStyle.verticalGap,
TableView(
headerText: 'SYNTAX HIGHLIGHTING',
items: [
TableViewItem(
text: Text('Light Mode'),
rightWidget: Text(codeProvider.theme),
onTap: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.theme,
items: CodeModel.themes
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (value) {
codeProvider.setTheme(value);
},
),
);
},
),
TableViewItem(
text: Text('Dark Mode'),
rightWidget: Text(codeProvider.themeDark),
onTap: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.themeDark,
items: CodeModel.themes
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (value) {
codeProvider.setThemeDark(value);
},
),
);
},
2019-09-25 08:24:20 +02:00
),
2020-01-12 10:13:48 +01:00
],
),
HighlightView(
_getCode(false),
language: 'dart',
theme: themeMap[codeProvider.theme],
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed,
2019-09-25 08:24:20 +02:00
),
2020-01-12 10:13:48 +01:00
padding: CommonStyle.padding,
),
HighlightView(
_getCode(true),
language: 'dart',
theme: themeMap[codeProvider.themeDark],
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed,
),
padding: CommonStyle.padding,
),
2019-09-25 08:24:20 +02:00
],
),
2019-09-15 11:36:09 +02:00
);
}
}