2022-09-20 20:00:03 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2019-09-15 11:36:09 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2019-09-15 11:36:09 +02:00
|
|
|
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';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
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
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.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(
|
2021-05-16 09:16:35 +02:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.codeTheme),
|
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,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-13 19:19:52 +02:00
|
|
|
header: Text(AppLocalizations.of(context)!.fontStyle),
|
2019-09-25 08:24:20 +02:00
|
|
|
items: [
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.fontSize),
|
|
|
|
extra: Text(codeProvider.fontSize.toString()),
|
|
|
|
onClick: () {
|
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) {
|
2021-05-16 09:16:35 +02:00
|
|
|
codeProvider.setFontSize(int.tryParse(value!) ?? 16);
|
2019-09-29 09:02:06 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2019-09-25 08:24:20 +02:00
|
|
|
},
|
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.fontFamily),
|
|
|
|
extra: Text(codeProvider.fontFamily),
|
|
|
|
onClick: () {
|
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(),
|
2021-05-16 09:16:35 +02:00
|
|
|
onChange: (String? value) {
|
|
|
|
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,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-13 19:19:52 +02:00
|
|
|
header: Text(AppLocalizations.of(context)!.syntaxHighlighting),
|
2020-01-12 10:13:48 +01:00
|
|
|
items: [
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.light),
|
|
|
|
extra: Text(codeProvider.theme),
|
|
|
|
onClick: () {
|
2020-01-12 10:13:48 +01:00
|
|
|
theme.showPicker(
|
|
|
|
context,
|
|
|
|
PickerGroupItem(
|
|
|
|
value: codeProvider.theme,
|
|
|
|
items: CodeModel.themes
|
|
|
|
.map((v) => PickerItem(v, text: v))
|
|
|
|
.toList(),
|
|
|
|
onChange: (value) {
|
2021-05-16 09:16:35 +02:00
|
|
|
codeProvider.setTheme(value!);
|
2020-01-12 10:13:48 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.dark),
|
|
|
|
extra: Text(codeProvider.themeDark),
|
|
|
|
onClick: () {
|
2020-01-12 10:13:48 +01:00
|
|
|
theme.showPicker(
|
|
|
|
context,
|
|
|
|
PickerGroupItem(
|
|
|
|
value: codeProvider.themeDark,
|
|
|
|
items: CodeModel.themes
|
|
|
|
.map((v) => PickerItem(v, text: v))
|
|
|
|
.toList(),
|
|
|
|
onChange: (value) {
|
2021-05-16 09:16:35 +02:00
|
|
|
codeProvider.setThemeDark(value!);
|
2020-01-12 10:13:48 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2019-09-25 08:24:20 +02:00
|
|
|
),
|
2020-01-12 10:13:48 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
HighlightView(
|
|
|
|
_getCode(false),
|
|
|
|
language: 'dart',
|
2021-05-16 09:16:35 +02:00
|
|
|
theme: themeMap[codeProvider.theme]!,
|
2021-07-20 08:33:34 +02:00
|
|
|
textStyle: codeProvider.fontStyle,
|
2020-01-12 10:13:48 +01:00
|
|
|
padding: CommonStyle.padding,
|
|
|
|
),
|
|
|
|
HighlightView(
|
|
|
|
_getCode(true),
|
|
|
|
language: 'dart',
|
2021-05-16 09:16:35 +02:00
|
|
|
theme: themeMap[codeProvider.themeDark]!,
|
2021-07-20 08:33:34 +02:00
|
|
|
textStyle: codeProvider.fontStyle,
|
2020-01-12 10:13:48 +01:00
|
|
|
padding: CommonStyle.padding,
|
|
|
|
),
|
2019-09-25 08:24:20 +02:00
|
|
|
],
|
|
|
|
),
|
2019-09-15 11:36:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|