File size: 4,120 Bytes
4547589
 
38048d1
f21ac8b
 
 
4547589
 
 
 
 
 
 
 
 
 
 
 
 
 
38048d1
4547589
 
 
 
 
38048d1
4547589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f21ac8b
 
 
 
 
4547589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38048d1
 
 
 
 
 
4547589
 
 
 
 
38048d1
4547589
f21ac8b
4547589
 
 
 
 
 
 
38048d1
4547589
 
 
38048d1
 
 
 
 
 
 
f21ac8b
 
38048d1
 
f21ac8b
38048d1
 
 
 
 
 
 
 
 
 
 
4547589
38048d1
4547589
38048d1
 
 
4547589
 
 
 
 
 
 
38048d1
4547589
 
 
 
 
 
38048d1
4547589
 
38048d1
4547589
 
 
 
7715c1b
f21ac8b
4547589
 
 
 
 
 
 
 
 
 
 
f21ac8b
4547589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'custom_color_picker_widget.dart';
import 'custom_button.dart';
import 'home_screen.dart';

class SetupScreen extends StatefulWidget{
  const SetupScreen({super.key});

  @override
  State<SetupScreen> createState(){
    return _SetupScreenState();
  }
}


class _SetupScreenState extends State<SetupScreen>{
  late TextEditingController textcontroller;
  late SharedPreferences prefs;
  late Color profileColor;

  @override
  void initState(){
    super.initState();
    textcontroller=TextEditingController();
    profileColor=Colors.red.shade200;
    loadPreferences();
  }  
  
  Future loadPreferences() async{
    prefs = await SharedPreferences.getInstance();
  }
  
  @override
  void dispose(){
    textcontroller.dispose();
    super.dispose();
  }

  Widget header(){
    return Column(
      children: [
        // Main Title
        const Text(
          "Haptic Link",
          style: TextStyle(
            fontSize: 40,
            fontWeight: FontWeight.w500,
          ),
        ),

        // Sub title
        Container(
          margin:const EdgeInsets.only(top:20),
          child:const Text(
            "Linking people with haptics",
            style: TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.w200,
            ),
          ),
        ),

      ],
    );  
  }

  void changeColor(color){
    setState((){
      profileColor=color;
    });
  }

  Widget footer(){
    return Column(
      children: [
        // Input fields
        Container(
          margin:const EdgeInsets.only(bottom:20),
          child:TextField(
            decoration:const InputDecoration(
              hintText: "Enter your first name",
              border:OutlineInputBorder(),
            ),
            style:const TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.w300,
            ),
            controller: textcontroller,   
          ),
        ),

        // Color Picker and Text in a row
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
          
          Container(
            margin:const EdgeInsets.only(right:20),
            child:const Text("Choose your Color"),
          ),

          CustomColorPickerWidget(
            pickerColor: profileColor, 
            // onColorChanged: (color){},
            onSubmit: changeColor,
            size:40,
          ),

        ]),
        
        // margin
        const SizedBox(height: 20,),

        // submit button
          CustomButton(
          onPressed: ()=>submit(),
          padding:const EdgeInsets.symmetric(vertical:15,horizontal: 20),
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(40)),
          ),
          child:const Text(
            "Join",
            style:TextStyle(
              fontSize:20,
            ),
          ),
        ),
      ],
    );  
  }

  void submit(){
    if(textcontroller.text.isNotEmpty){
      // save username & profileColor to Shared Preferences
      prefs.setBool("setup_done", true);
      prefs.setString("username", textcontroller.text);
      prefs.setString("profile_color", colorToHex(profileColor));
      // go to Lobby
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(
          // builder: (context)=>LobbyScreen()
          builder: (context)=>const HomeScreen()
          ),
        
        );
    }
  }


  @override
  Widget build(BuildContext context){
    return Scaffold(
      body:Container(
        padding:const EdgeInsets.all(20),

        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            // crossAxisAlignment: CrossAxisAlignment,
            children: [

              header(),
              
              footer(),

            ],
          ),
        ),
      ),
    );
  }
}