Replace color picker

This commit is contained in:
stonegate 2020-05-08 23:22:31 +08:00
parent 2e10a0aa94
commit 40e2d880b5
6 changed files with 170 additions and 12 deletions

View File

@ -21,6 +21,6 @@ jobs:
command: flutter build appbundle --no-shrink
- run:
name: Build the Android apks
command: flutter build build apk --split-per-abi --no-shrink
command: flutter build apk --split-per-abi --no-shrink
- store_artifacts:
path: build/app/outputs/

View File

@ -47,7 +47,7 @@ android {
applicationId "com.stonegate.tsacdop"
minSdkVersion 19
targetSdkVersion 28
versionCode 10
versionCode 11
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -53,6 +53,7 @@ class MyApp extends StatelessWidget {
title: 'Tsacdop',
theme: lightTheme.copyWith(
accentColor: setting.accentSetColor,
toggleableActiveColor: setting.accentSetColor
),
darkTheme: ThemeData.dark().copyWith(
accentColor: setting.accentSetColor,

View File

@ -54,8 +54,6 @@ List<Libries> plugins = [
Libries('cached_network_image', mit,
'https://pub.dev/packages/cached_network_image'),
Libries('workmanager', mit, 'https://pub.dev/packages/workmanager'),
Libries('flutter_colorpicker', mit,
'https://pub.dev/packages/flutter_colorpicker'),
Libries('app_settings', mit, 'https://pub.dev/packages/app_settings'),
Libries('fl_chart', bsd, 'https://pub.dev/packages/fl_chart'),
Libries('audio_service', mit, 'https://pub.dev/packages/audio_service'),

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import '../state/settingstate.dart';
import '../util/context_extension.dart';
@ -169,12 +168,17 @@ class ThemeSetting extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0))),
title: Text('Choose a color'),
content: MaterialPicker(
onColorChanged: (value) {
settings.setAccentColor = value;
},
pickerColor: context.accentColor,
title: Text.rich(
TextSpan(text: 'Choose a ', children: [
TextSpan(
text: 'color',
style: TextStyle(
fontWeight: FontWeight.bold,
color: context.accentColor))
])),
content: ColorPicker(
onColorChanged: (value) =>
settings.setAccentColor = value,
),
))),
contentPadding: EdgeInsets.only(left: 80.0, right: 25),
@ -197,4 +201,160 @@ class ThemeSetting extends StatelessWidget {
),
);
}
}
class ColorPicker extends StatefulWidget {
final ValueChanged<Color> onColorChanged;
ColorPicker({Key key, this.onColorChanged}) : super(key: key);
@override
_ColorPickerState createState() => _ColorPickerState();
}
class _ColorPickerState extends State<ColorPicker>
with SingleTickerProviderStateMixin {
TabController _controller;
int _index;
@override
void initState() {
super.initState();
_index = 0;
_controller = TabController(length: Colors.primaries.length, vsync: this)
..addListener(() {
setState(() => _index = _controller.index);
});
}
Widget _colorCircle(Color color) => Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.all(Radius.circular(10)),
onTap: () => widget.onColorChanged(color),
child: Container(
decoration: BoxDecoration(
border: color == context.accentColor
? Border.all(color: Colors.grey[400], width: 4)
: null,
borderRadius: BorderRadius.all(Radius.circular(10)),
color: color),
),
),
);
List<Widget> _accentList(MaterialAccentColor color) => [
_colorCircle(color.shade100),
_colorCircle(color.shade200),
_colorCircle(color.shade400),
_colorCircle(color.shade700)
];
@override
Widget build(BuildContext context) {
return Container(
width: 200,
height: 400,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 40,
color: Theme.of(context).dialogBackgroundColor,
child: TabBar(
labelPadding: EdgeInsets.symmetric(horizontal: 10),
controller: _controller,
indicatorColor: Colors.transparent,
indicatorSize: TabBarIndicatorSize.tab,
isScrollable: true,
tabs: Colors.primaries
.map<Widget>((color) => Tab(
child: Container(
height: 20,
width: 40,
decoration: BoxDecoration(
border: Colors.primaries.indexOf(color) == _index
? Border.all(
color: Colors.grey[400], width: 2)
: null,
borderRadius:
BorderRadius.all(Radius.circular(10)),
color: color),
),
))
.toList(),
),
),
Expanded(
child: TabBarView(
key: UniqueKey(),
controller: _controller,
children: Colors.primaries
.map<Widget>((color) => GridView.count(
primary: false,
padding: const EdgeInsets.all(10),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 3,
children: <Widget>[
_colorCircle(color.shade100),
_colorCircle(color.shade200),
_colorCircle(color.shade300),
_colorCircle(color.shade400),
_colorCircle(color.shade500),
_colorCircle(color.shade600),
_colorCircle(color.shade700),
_colorCircle(color.shade800),
_colorCircle(color.shade900),
...color == Colors.red
? _accentList(Colors.redAccent)
: color == Colors.pink
? _accentList(Colors.pinkAccent)
: color == Colors.deepOrange
? _accentList(Colors.deepOrangeAccent)
: color == Colors.orange
? _accentList(Colors.orangeAccent)
: color == Colors.amber
? _accentList(Colors.amberAccent)
: color == Colors.yellow
? _accentList(
Colors.yellowAccent)
: color == Colors.lime
? _accentList(
Colors.limeAccent)
: color ==
Colors.lightGreen
? _accentList(Colors
.lightGreenAccent)
: color == Colors.green
? _accentList(Colors
.greenAccent)
: color ==
Colors
.teal
? _accentList(
Colors
.tealAccent)
: color ==
Colors
.cyan
? _accentList(
Colors
.cyanAccent)
: color ==
Colors
.lightBlue
? _accentList(Colors
.lightBlueAccent)
: color == Colors.blue
? _accentList(Colors.blueAccent)
: color == Colors.indigo ? _accentList(Colors.indigoAccent) : color == Colors.purple ? _accentList(Colors.purpleAccent) : color == Colors.deepPurple ? _accentList(Colors.deepPurpleAccent) : []
],
))
.toList(),
),
),
],
),
);
}
}

View File

@ -37,7 +37,6 @@ dev_dependencies:
tuple: ^1.0.3
cached_network_image: ^2.1.0+1
workmanager: ^0.2.2
flutter_colorpicker: ^0.3.4
fl_chart: ^0.9.3
audio_service: ^0.8.0
flutter_file_dialog: ^0.0.5