diff --git a/lib/main.dart b/lib/main.dart index e71644cb4342059745b2b1e418c32130d01daabd..8a1acb38974403f881649485774fb5fc29dc415b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -74,7 +74,7 @@ class _HUDState extends State<HUD> { }, children: const [ HomePage(), - emptyMoodpage(), + StateMoodPage(), StateSearcgPage(), ], ), diff --git a/lib/moodpage.dart b/lib/moodpage.dart index 697babd2dc8feab786aa6995eea72d6094a68b6b..3a0d0cbe2c443fc92363116d95dd73e96a161ef9 100644 --- a/lib/moodpage.dart +++ b/lib/moodpage.dart @@ -1,5 +1,5 @@ -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), ),