Spaces:
Paused
Paused
Commit
·
38048d1
1
Parent(s):
4547589
added colorpicker on setup screen
Browse files- client/lib/Colors/CustomColorPicker.dart +109 -0
- client/lib/CustomButton.dart +30 -0
- client/lib/LobbyScreen.dart +26 -3
- client/lib/SetupScreen.dart +43 -14
- client/pubspec.lock +8 -0
- client/pubspec.yaml +1 -0
client/lib/Colors/CustomColorPicker.dart
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import 'package:flutter/material.dart';
|
| 2 |
+
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
| 3 |
+
import '../CustomButton.dart';
|
| 4 |
+
|
| 5 |
+
class CustomColorPicker extends StatefulWidget{
|
| 6 |
+
CustomColorPicker({
|
| 7 |
+
Key? key,
|
| 8 |
+
required this.pickerColor,
|
| 9 |
+
required this.onSubmit,
|
| 10 |
+
required this.size,
|
| 11 |
+
}):super(key:key);
|
| 12 |
+
|
| 13 |
+
Color pickerColor;
|
| 14 |
+
final void Function(Color) onSubmit;
|
| 15 |
+
final double size;
|
| 16 |
+
|
| 17 |
+
@override
|
| 18 |
+
State<CustomColorPicker> createState(){
|
| 19 |
+
return CustomColorPickerState();
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
class CustomColorPickerState extends State<CustomColorPicker>{
|
| 25 |
+
late Color pickerColor;
|
| 26 |
+
void initState(){
|
| 27 |
+
setState(() {
|
| 28 |
+
pickerColor=widget.pickerColor;
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
void changeColor(color){
|
| 32 |
+
setState((){
|
| 33 |
+
pickerColor=color;
|
| 34 |
+
});
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
Widget buildColorPicker(){
|
| 38 |
+
// return ColorPicker(
|
| 39 |
+
return HueRingPicker(
|
| 40 |
+
pickerColor: widget.pickerColor,
|
| 41 |
+
onColorChanged: changeColor,
|
| 42 |
+
portraitOnly:true,
|
| 43 |
+
// enableAlpha: false,
|
| 44 |
+
// colorPickerHeight: 100,
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
@override
|
| 51 |
+
Widget build(BuildContext context){
|
| 52 |
+
|
| 53 |
+
return InkWell(
|
| 54 |
+
|
| 55 |
+
onTap: (){
|
| 56 |
+
|
| 57 |
+
showDialog(
|
| 58 |
+
context: context,
|
| 59 |
+
builder: (context){
|
| 60 |
+
return AlertDialog(
|
| 61 |
+
content:SingleChildScrollView(
|
| 62 |
+
child:Column(
|
| 63 |
+
children: [
|
| 64 |
+
// color picker widget
|
| 65 |
+
buildColorPicker(),
|
| 66 |
+
|
| 67 |
+
// submit button
|
| 68 |
+
CustomButton(
|
| 69 |
+
onPressed: (){
|
| 70 |
+
Navigator.pop(context);
|
| 71 |
+
widget.onSubmit(pickerColor);
|
| 72 |
+
},
|
| 73 |
+
child:const Text(
|
| 74 |
+
"Submit",
|
| 75 |
+
),
|
| 76 |
+
)
|
| 77 |
+
],
|
| 78 |
+
),
|
| 79 |
+
),
|
| 80 |
+
|
| 81 |
+
);
|
| 82 |
+
// return buildColorPicker();
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
},
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
customBorder:const CircleBorder(),
|
| 91 |
+
|
| 92 |
+
child:Container(
|
| 93 |
+
width:widget.size,
|
| 94 |
+
height:widget.size,
|
| 95 |
+
margin:const EdgeInsets.all(0),
|
| 96 |
+
decoration: BoxDecoration(
|
| 97 |
+
shape:BoxShape.circle,
|
| 98 |
+
color:widget.pickerColor,
|
| 99 |
+
),
|
| 100 |
+
// style:TextStyle(
|
| 101 |
+
// fontSize:20,
|
| 102 |
+
// // color: widget.pickerColor,
|
| 103 |
+
// ),
|
| 104 |
+
|
| 105 |
+
),
|
| 106 |
+
);
|
| 107 |
+
|
| 108 |
+
}
|
| 109 |
+
}
|
client/lib/CustomButton.dart
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import 'package:flutter/material.dart';
|
| 2 |
+
|
| 3 |
+
class CustomButton extends StatelessWidget{
|
| 4 |
+
final Widget child;
|
| 5 |
+
final VoidCallback onPressed;
|
| 6 |
+
final EdgeInsets padding;
|
| 7 |
+
final OutlinedBorder? shape;
|
| 8 |
+
const CustomButton({
|
| 9 |
+
super.key,
|
| 10 |
+
required this.onPressed,
|
| 11 |
+
required this.child,
|
| 12 |
+
this.padding = const EdgeInsets.symmetric(vertical:15,horizontal: 20),
|
| 13 |
+
this.shape = const RoundedRectangleBorder(
|
| 14 |
+
borderRadius: BorderRadius.all(Radius.circular(40)),
|
| 15 |
+
),
|
| 16 |
+
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
@override
|
| 20 |
+
Widget build(BuildContext context){
|
| 21 |
+
return ElevatedButton(
|
| 22 |
+
onPressed: onPressed,
|
| 23 |
+
style:ElevatedButton.styleFrom(
|
| 24 |
+
padding:padding,
|
| 25 |
+
shape: shape,
|
| 26 |
+
),
|
| 27 |
+
child:child,
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
}
|
client/lib/LobbyScreen.dart
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import 'package:flutter/material.dart';
|
| 2 |
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
| 3 |
|
| 4 |
class LobbyScreen extends StatefulWidget{
|
| 5 |
|
|
@@ -14,11 +15,13 @@ class LobbyScreenState extends State<LobbyScreen>{
|
|
| 14 |
late SharedPreferences prefs;
|
| 15 |
// final Future<SharedPreferences> prefs=SharedPreferences.getInstance();
|
| 16 |
late String username;
|
|
|
|
| 17 |
|
| 18 |
@override
|
| 19 |
void initState(){
|
| 20 |
super.initState();
|
| 21 |
username="";
|
|
|
|
| 22 |
loadPreferences();
|
| 23 |
deletePreference();
|
| 24 |
}
|
|
@@ -26,19 +29,39 @@ class LobbyScreenState extends State<LobbyScreen>{
|
|
| 26 |
prefs = await SharedPreferences.getInstance();
|
| 27 |
setState(() {
|
| 28 |
username= prefs.getString("username")!;
|
|
|
|
| 29 |
});
|
| 30 |
}
|
| 31 |
void deletePreference() async{
|
| 32 |
prefs = await SharedPreferences.getInstance();
|
| 33 |
prefs.remove('setup_done');
|
| 34 |
prefs.remove('username');
|
|
|
|
| 35 |
}
|
| 36 |
@override
|
| 37 |
Widget build(BuildContext context){
|
| 38 |
return Scaffold(
|
| 39 |
-
body:
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
);
|
| 43 |
}
|
| 44 |
}
|
|
|
|
| 1 |
import 'package:flutter/material.dart';
|
| 2 |
import 'package:shared_preferences/shared_preferences.dart';
|
| 3 |
+
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
| 4 |
|
| 5 |
class LobbyScreen extends StatefulWidget{
|
| 6 |
|
|
|
|
| 15 |
late SharedPreferences prefs;
|
| 16 |
// final Future<SharedPreferences> prefs=SharedPreferences.getInstance();
|
| 17 |
late String username;
|
| 18 |
+
late Color profileColor;
|
| 19 |
|
| 20 |
@override
|
| 21 |
void initState(){
|
| 22 |
super.initState();
|
| 23 |
username="";
|
| 24 |
+
profileColor=Colors.black;
|
| 25 |
loadPreferences();
|
| 26 |
deletePreference();
|
| 27 |
}
|
|
|
|
| 29 |
prefs = await SharedPreferences.getInstance();
|
| 30 |
setState(() {
|
| 31 |
username= prefs.getString("username")!;
|
| 32 |
+
profileColor= colorFromHex(prefs.getString("profile_color")!)!;
|
| 33 |
});
|
| 34 |
}
|
| 35 |
void deletePreference() async{
|
| 36 |
prefs = await SharedPreferences.getInstance();
|
| 37 |
prefs.remove('setup_done');
|
| 38 |
prefs.remove('username');
|
| 39 |
+
prefs.remove('profile_color');
|
| 40 |
}
|
| 41 |
@override
|
| 42 |
Widget build(BuildContext context){
|
| 43 |
return Scaffold(
|
| 44 |
+
body:Row(
|
| 45 |
+
children: [
|
| 46 |
+
|
| 47 |
+
Expanded(
|
| 48 |
+
child:Column(
|
| 49 |
+
mainAxisAlignment: MainAxisAlignment.center,
|
| 50 |
+
crossAxisAlignment: CrossAxisAlignment.center,
|
| 51 |
+
children:[
|
| 52 |
+
Expanded(
|
| 53 |
+
child: Container(
|
| 54 |
+
child:Text("yooooo ${username}"),
|
| 55 |
+
decoration:BoxDecoration(
|
| 56 |
+
color:profileColor,
|
| 57 |
+
),
|
| 58 |
+
),
|
| 59 |
+
),
|
| 60 |
+
]),
|
| 61 |
+
|
| 62 |
+
),
|
| 63 |
+
])
|
| 64 |
+
|
| 65 |
);
|
| 66 |
}
|
| 67 |
}
|
client/lib/SetupScreen.dart
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import 'package:flutter/material.dart';
|
| 2 |
import 'package:shared_preferences/shared_preferences.dart';
|
| 3 |
import 'package:hapticlink/LobbyScreen.dart';
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
class SetupScreen extends StatefulWidget{
|
| 7 |
const SetupScreen({super.key});
|
|
@@ -16,11 +18,13 @@ class SetupScreen extends StatefulWidget{
|
|
| 16 |
class _SetupScreenState extends State<SetupScreen>{
|
| 17 |
late TextEditingController textcontroller;
|
| 18 |
late SharedPreferences prefs;
|
|
|
|
| 19 |
|
| 20 |
@override
|
| 21 |
void initState(){
|
| 22 |
super.initState();
|
| 23 |
textcontroller=TextEditingController();
|
|
|
|
| 24 |
loadPreferences();
|
| 25 |
}
|
| 26 |
|
|
@@ -65,12 +69,18 @@ class _SetupScreenState extends State<SetupScreen>{
|
|
| 65 |
);
|
| 66 |
}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
Widget footer(){
|
| 69 |
return Column(
|
| 70 |
children: [
|
| 71 |
// Input fields
|
| 72 |
Container(
|
| 73 |
-
margin:const EdgeInsets.only(bottom:
|
| 74 |
child:TextField(
|
| 75 |
decoration: InputDecoration(
|
| 76 |
hintText: "Enter your first name",
|
|
@@ -80,38 +90,57 @@ class _SetupScreenState extends State<SetupScreen>{
|
|
| 80 |
fontSize: 20,
|
| 81 |
fontWeight: FontWeight.w300,
|
| 82 |
),
|
| 83 |
-
controller: textcontroller,
|
| 84 |
-
onSubmitted: (value) => submit(),
|
| 85 |
),
|
| 86 |
),
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
// submit button
|
| 89 |
-
|
| 90 |
onPressed: ()=>submit(),
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
shape: const RoundedRectangleBorder(
|
| 95 |
-
borderRadius: BorderRadius.all(Radius.circular(40)),
|
| 96 |
-
),
|
| 97 |
),
|
| 98 |
child:const Text(
|
| 99 |
"Join",
|
| 100 |
style:TextStyle(
|
| 101 |
fontSize:20,
|
| 102 |
),
|
| 103 |
-
|
| 104 |
),
|
| 105 |
-
)
|
| 106 |
],
|
| 107 |
);
|
| 108 |
}
|
| 109 |
|
| 110 |
void submit(){
|
| 111 |
if(textcontroller.text.isNotEmpty){
|
| 112 |
-
// save username to Shared Preferences
|
| 113 |
prefs.setBool("setup_done", true);
|
| 114 |
prefs.setString("username", textcontroller.text);
|
|
|
|
| 115 |
// go to Lobby
|
| 116 |
Navigator.pushReplacement(
|
| 117 |
context,
|
|
|
|
| 1 |
import 'package:flutter/material.dart';
|
| 2 |
import 'package:shared_preferences/shared_preferences.dart';
|
| 3 |
import 'package:hapticlink/LobbyScreen.dart';
|
| 4 |
+
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
| 5 |
+
import 'Colors/CustomColorPicker.dart';
|
| 6 |
+
import "CustomButton.dart";
|
| 7 |
|
| 8 |
class SetupScreen extends StatefulWidget{
|
| 9 |
const SetupScreen({super.key});
|
|
|
|
| 18 |
class _SetupScreenState extends State<SetupScreen>{
|
| 19 |
late TextEditingController textcontroller;
|
| 20 |
late SharedPreferences prefs;
|
| 21 |
+
late Color profileColor;
|
| 22 |
|
| 23 |
@override
|
| 24 |
void initState(){
|
| 25 |
super.initState();
|
| 26 |
textcontroller=TextEditingController();
|
| 27 |
+
profileColor=Colors.red.shade200;
|
| 28 |
loadPreferences();
|
| 29 |
}
|
| 30 |
|
|
|
|
| 69 |
);
|
| 70 |
}
|
| 71 |
|
| 72 |
+
void changeColor(color){
|
| 73 |
+
setState((){
|
| 74 |
+
profileColor=color;
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
Widget footer(){
|
| 79 |
return Column(
|
| 80 |
children: [
|
| 81 |
// Input fields
|
| 82 |
Container(
|
| 83 |
+
margin:const EdgeInsets.only(bottom:20),
|
| 84 |
child:TextField(
|
| 85 |
decoration: InputDecoration(
|
| 86 |
hintText: "Enter your first name",
|
|
|
|
| 90 |
fontSize: 20,
|
| 91 |
fontWeight: FontWeight.w300,
|
| 92 |
),
|
| 93 |
+
controller: textcontroller,
|
|
|
|
| 94 |
),
|
| 95 |
),
|
| 96 |
|
| 97 |
+
// Color Picker and Text in a row
|
| 98 |
+
Row(
|
| 99 |
+
mainAxisAlignment: MainAxisAlignment.center,
|
| 100 |
+
crossAxisAlignment: CrossAxisAlignment.center,
|
| 101 |
+
children: [
|
| 102 |
+
|
| 103 |
+
Container(
|
| 104 |
+
margin:EdgeInsets.only(right:20),
|
| 105 |
+
child:Text("Choose your Color"),
|
| 106 |
+
),
|
| 107 |
+
|
| 108 |
+
CustomColorPicker(
|
| 109 |
+
pickerColor: profileColor,
|
| 110 |
+
// onColorChanged: (color){},
|
| 111 |
+
onSubmit: changeColor,
|
| 112 |
+
size:40,
|
| 113 |
+
),
|
| 114 |
+
|
| 115 |
+
]),
|
| 116 |
+
|
| 117 |
+
// margin
|
| 118 |
+
const SizedBox(height: 20,),
|
| 119 |
+
|
| 120 |
// submit button
|
| 121 |
+
CustomButton(
|
| 122 |
onPressed: ()=>submit(),
|
| 123 |
+
padding:const EdgeInsets.symmetric(vertical:15,horizontal: 20),
|
| 124 |
+
shape: const RoundedRectangleBorder(
|
| 125 |
+
borderRadius: BorderRadius.all(Radius.circular(40)),
|
|
|
|
|
|
|
|
|
|
| 126 |
),
|
| 127 |
child:const Text(
|
| 128 |
"Join",
|
| 129 |
style:TextStyle(
|
| 130 |
fontSize:20,
|
| 131 |
),
|
|
|
|
| 132 |
),
|
| 133 |
+
),
|
| 134 |
],
|
| 135 |
);
|
| 136 |
}
|
| 137 |
|
| 138 |
void submit(){
|
| 139 |
if(textcontroller.text.isNotEmpty){
|
| 140 |
+
// save username & profileColor to Shared Preferences
|
| 141 |
prefs.setBool("setup_done", true);
|
| 142 |
prefs.setString("username", textcontroller.text);
|
| 143 |
+
prefs.setString("profile_color", colorToHex(profileColor));
|
| 144 |
// go to Lobby
|
| 145 |
Navigator.pushReplacement(
|
| 146 |
context,
|
client/pubspec.lock
CHANGED
|
@@ -78,6 +78,14 @@ packages:
|
|
| 78 |
description: flutter
|
| 79 |
source: sdk
|
| 80 |
version: "0.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
flutter_lints:
|
| 82 |
dependency: "direct dev"
|
| 83 |
description:
|
|
|
|
| 78 |
description: flutter
|
| 79 |
source: sdk
|
| 80 |
version: "0.0.0"
|
| 81 |
+
flutter_colorpicker:
|
| 82 |
+
dependency: "direct main"
|
| 83 |
+
description:
|
| 84 |
+
name: flutter_colorpicker
|
| 85 |
+
sha256: "458a6ed8ea480eb16ff892aedb4b7092b2804affd7e046591fb03127e8d8ef8b"
|
| 86 |
+
url: "https://pub.dev"
|
| 87 |
+
source: hosted
|
| 88 |
+
version: "1.0.3"
|
| 89 |
flutter_lints:
|
| 90 |
dependency: "direct dev"
|
| 91 |
description:
|
client/pubspec.yaml
CHANGED
|
@@ -10,6 +10,7 @@ dependencies:
|
|
| 10 |
after_layout: ^1.2.0
|
| 11 |
flutter:
|
| 12 |
sdk: flutter
|
|
|
|
| 13 |
shared_preferences: ^2.2.2
|
| 14 |
|
| 15 |
dev_dependencies:
|
|
|
|
| 10 |
after_layout: ^1.2.0
|
| 11 |
flutter:
|
| 12 |
sdk: flutter
|
| 13 |
+
flutter_colorpicker: ^1.0.3
|
| 14 |
shared_preferences: ^2.2.2
|
| 15 |
|
| 16 |
dev_dependencies:
|