Skip to content
Snippets Groups Projects
Commit 6afc269a authored by Ede Dust's avatar Ede Dust
Browse files

mergeVonEde

parent f6c7b425
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,6 @@ import 'homepage.dart';
import 'moodpage.dart';
import 'searchpage.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp;
......
import 'package:ambient/widgets/navbars.dart';
import 'dart:io';
import 'package:vector_math/vector_math.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';
import 'package:palette_generator/palette_generator.dart';
......@@ -11,10 +11,26 @@ class StateMoodPage extends StatefulWidget {
State<StateMoodPage> createState() => MoodPage();
}
enum Moods { none, happy, sad }
extension MoodsExtention on Moods {
Color get color {
switch (this) {
case Moods.none:
return Color.fromARGB(255, 75, 75, 75);
case Moods.happy:
return Color.fromARGB(255, 237, 219, 18);
case Moods.sad:
return Color.fromARGB(255, 64, 71, 167);
}
}
}
class MoodPage extends State<StateMoodPage> {
late File _image;
final ImagePicker _picker = ImagePicker();
late PaletteGenerator paletteGenerator;
Moods? currentMood = Moods.happy;
String imagePath = "";
_getFromGallery() async {
......@@ -34,6 +50,54 @@ class MoodPage extends State<StateMoodPage> {
}
}
_getColorDistance(Color c1, Color c2) {
double distance = 0;
Vector3 v1 =
Vector3(c1.red.toDouble(), c1.green.toDouble(), c1.blue.toDouble());
Vector3 v2 =
Vector3(c2.red.toDouble(), c2.green.toDouble(), c2.blue.toDouble());
distance = v1.distanceTo(v2).toInt().toDouble();
return distance;
}
_determineMoodToMatch(Color col) {
double distance = 1000.0;
Moods newMood = Moods.none;
for (var value in Moods.values) {
if (_getColorDistance(col, value.color) < distance &&
value != Moods.none) {
distance = _getColorDistance(col, value.color);
newMood = value;
}
}
return newMood;
}
_getMoodList() {
return Column(children: <Widget>[
RadioListTile<Moods>(
title: const Text('Happy'),
value: Moods.happy,
groupValue: currentMood,
onChanged: (Moods? value) {
setState(() {
currentMood = value;
});
},
),
RadioListTile<Moods>(
title: const Text('Sad'),
value: Moods.sad,
groupValue: currentMood,
onChanged: (Moods? value) {
setState(() {
currentMood = value;
});
},
),
]);
}
_getContainerTodisplay() {
BoxDecoration deco = new BoxDecoration();
var image;
......@@ -46,8 +110,8 @@ class MoodPage extends State<StateMoodPage> {
),
);
} else {
deco = new BoxDecoration(
color: Colors.purple,
deco = const BoxDecoration(
color: Color.fromARGB(255, 64, 71, 167),
);
}
return Container(
......@@ -83,11 +147,14 @@ class MoodPage extends State<StateMoodPage> {
(BuildContext context, AsyncSnapshot<PaletteGenerator> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
return const Center(child: CircularProgressIndicator());
default:
if (snapshot.hasError) {
return PaletteSquare(color: Color.fromARGB(255, 236, 177, 173));
return const PaletteSquare(
color: Color.fromARGB(255, 173, 188, 236));
} else {
currentMood =
_determineMoodToMatch(snapshot.data!.dominantColor!.color);
return Row(children: <Widget>[
PaletteSquare(color: snapshot.data!.mutedColor!.color),
PaletteSquare(color: snapshot.data!.vibrantColor!.color),
......@@ -103,16 +170,19 @@ class MoodPage extends State<StateMoodPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("MoodPage"),
),
body: Center(
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_getContainerTodisplay(),
_getCollorIndicator(),
_getMoodList(),
TextButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all(Theme.of(context).hintColor),
foregroundColor: MaterialStateProperty.all(
Theme.of(context).primaryColorLight),
backgroundColor: MaterialStateProperty.all(
Theme.of(context).backgroundColor),
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment