git-touch-android-ios-app/lib/screens/code_settings.dart

77 lines
2.6 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';
import 'package:git_touch/scaffolds/simple.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-19 16:01:30 +02:00
import 'package:git_touch/widgets/picker.dart';
2019-09-15 11:36:09 +02:00
import 'package:provider/provider.dart';
class CodeSettingsScreen extends StatelessWidget {
final String code;
final String language;
CodeSettingsScreen(this.code, this.language);
@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>[
2019-09-19 16:01:30 +02:00
PickerGroup(
2019-09-15 11:36:09 +02:00
items: [
2019-09-19 16:01:30 +02:00
PickerGroupItem(
title: 'Syntax Highlighting',
value: codeProvider.theme,
items: CodeModel.themes.map((v) => PickerItem(v, text: v)),
onChange: (value) {
Provider.of<CodeModel>(context).setTheme(value);
2019-09-19 15:10:50 +02:00
},
),
2019-09-19 16:01:30 +02:00
PickerGroupItem(
title: 'Font Size',
value: codeProvider.fontSize.toString(),
items: CodeModel.fontSizes
.map((v) => PickerItem(v.toString(), text: v.toString())),
onChange: (value) {
Provider.of<CodeModel>(context)
.setFontSize(int.tryParse(value) ?? 16);
2019-09-15 11:36:09 +02:00
},
),
2019-09-19 16:01:30 +02:00
PickerGroupItem(
title: 'Font Family',
value: codeProvider.fontFamily,
items:
CodeModel.fontFamilies.map((v) => PickerItem(v, text: v)),
onChange: (String value) {
Provider.of<CodeModel>(context).setFontFamily(value);
2019-09-15 11:36:09 +02:00
},
),
],
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: HighlightView(
code,
language: language,
theme: themeMap[codeProvider.theme],
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
2019-09-15 12:27:46 +02:00
fontFamily: codeProvider.fontFamilyUsed,
2019-09-15 11:36:09 +02:00
),
padding: const EdgeInsets.all(10),
),
)
],
);
},
);
}
}