contact_us2.dart 12.1 KB
Newer Older
r.manan@eksad.com's avatar
r.manan@eksad.com committed
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
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
// import 'package:mcs_flutter/widget/botton.dart';
// import 'package:mcs_flutter/const/conts.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:medapp_eksad/widget/button_color.dart';

class ContactUs2 extends StatelessWidget {
  ContactUs2({Key? key}) : super(key: key);

  final _formKey = GlobalKey<FormState>();

  final nameController = TextEditingController();
  final phoneController = TextEditingController();
  final emailController = TextEditingController();
  final messageController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    var screenSize = MediaQuery.of(context).size;
    return Container(
      height: 480,
      width: screenSize.width,
      // color: Colors.blue,
      decoration: const BoxDecoration(
          gradient: LinearGradient(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
28 29 30 31 32 33 34 35
        colors: <Color>[
          Color(0xff137fc2),
          Color(0xff3958d5),
          Color(0xff184b80),
        ],
        begin: Alignment.topCenter,
        end: Alignment.bottomCenter,
      )),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
36 37 38 39 40
      child: Row(
        children: [
          const Spacer(
            flex: 3,
          ),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
41
          SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
42 43 44 45 46 47 48 49
            height: screenSize.height * 0.7,
            width: screenSize.width * 0.35,
            child: Container(
              padding: const EdgeInsets.all(10),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
r.manan@eksad.com's avatar
r.manan@eksad.com committed
50
                  SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
51 52 53
                    height: screenSize.height * 0.23,
                    child: Text(
                        'Yes, you need '
r.manan@eksad.com's avatar
r.manan@eksad.com committed
54 55 56
                        '\n'
                        'an outsourcing partner '
                        'you can trust and thrive with',
r.manan@eksad.com's avatar
r.manan@eksad.com committed
57 58 59 60 61 62 63 64 65
                        textAlign: TextAlign.justify,
                        style: GoogleFonts.poppins(
                            color: Colors.white,
                            fontSize: 30,
                            fontWeight: FontWeight.bold)),
                  ),
                  const Spacer(
                    flex: 1,
                  ),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
66
                  SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
67 68 69
                    height: screenSize.height * 0.3,
                    child: Text(
                        'Go for the one who knows what they are doing, those who you share values with, '
r.manan@eksad.com's avatar
r.manan@eksad.com committed
70 71
                        'and those who will celebrate your success, and help you win over your biggest challenges. '
                        '\nLooking for an outsourcing partner? ',
r.manan@eksad.com's avatar
r.manan@eksad.com committed
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
                        textAlign: TextAlign.justify,
                        style: GoogleFonts.poppins(
                            color: Colors.white,
                            fontSize: 18,
                            // fontWeight: FontWeight.bold,
                            letterSpacing: 1.1)),
                  ),
                  const Spacer(
                    flex: 1,
                  ),
                  Text("We’ll contact you immediately to discuss to help you.",
                      style: GoogleFonts.poppins(
                          color: Colors.white,
                          fontSize: 18,
                          letterSpacing: 1.2)),
                  const Spacer(
                    flex: 2,
                  ),
                ],
              ),
            ),
          ),
          const Spacer(),
          Container(
            padding: const EdgeInsets.all(15),
            height: screenSize.height * 0.7,
            width: screenSize.width * 0.4,
            child: Form(
              key: _formKey,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Text(
                    "Name",
                    style: GoogleFonts.poppins(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.w400),
                  ),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
112
                  SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
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
                    width: 450,
                    child: TextFormField(
                      controller: nameController,
                      decoration: const InputDecoration(
                        hintText: "Enter your Name",
                        fillColor: Colors.white,
                        filled: true,
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.zero,
                          borderSide: BorderSide(width: 1, color: Colors.white),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.zero,
                          borderSide: BorderSide(width: 1, color: Colors.white),
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Row(
                    children: [
                      Text(
                        "Phone Number",
                        style: GoogleFonts.poppins(
                            color: Colors.white,
                            fontSize: 20,
                            fontWeight: FontWeight.w400),
                      ),
                      const SizedBox(
                        width: 80,
                      ),
                      Text(
                        "Email",
                        style: GoogleFonts.poppins(
                            color: Colors.white,
                            fontSize: 20,
                            fontWeight: FontWeight.w400),
                      ),
                    ],
                  ),
                  Row(
                    children: [
r.manan@eksad.com's avatar
r.manan@eksad.com committed
157
                      SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
158 159 160 161 162 163 164 165 166 167
                        width: 220,
                        child: TextFormField(
                          controller: phoneController,
                          decoration: const InputDecoration(
                            hintText: "Enter a valid phone number",
                            fillColor: Colors.white,
                            filled: true,
                            enabledBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.zero,
                              borderSide:
r.manan@eksad.com's avatar
r.manan@eksad.com committed
168
                                  BorderSide(width: 1, color: Colors.white),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
169 170 171 172
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.zero,
                              borderSide:
r.manan@eksad.com's avatar
r.manan@eksad.com committed
173
                                  BorderSide(width: 1, color: Colors.white),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
174 175 176 177 178 179 180
                            ),
                          ),
                        ),
                      ),
                      const SizedBox(
                        width: 7,
                      ),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
181
                      SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
182 183 184 185 186 187 188 189 190 191
                        width: 220,
                        child: TextFormField(
                          controller: emailController,
                          decoration: const InputDecoration(
                            hintText: "Enter a valid email address",
                            fillColor: Colors.white,
                            filled: true,
                            enabledBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.zero,
                              borderSide:
r.manan@eksad.com's avatar
r.manan@eksad.com committed
192
                                  BorderSide(width: 1, color: Colors.white),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
193 194 195 196
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.zero,
                              borderSide:
r.manan@eksad.com's avatar
r.manan@eksad.com committed
197
                                  BorderSide(width: 1, color: Colors.white),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
                            ),
                          ),
                        ),
                      ),
                      const SizedBox(
                        height: 20,
                      ),
                    ],
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Text(
                    "Message",
                    style: GoogleFonts.poppins(
                        color: Colors.white,
                        fontSize: 20,
                        fontWeight: FontWeight.w400),
                  ),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
217
                  SizedBox(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
                    width: 450,
                    height: 107,
                    child: TextFormField(
                      controller: messageController,
                      decoration: const InputDecoration(
                        hintText: "Enter your message",
                        fillColor: Colors.white,
                        filled: true,
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.zero,
                          borderSide: BorderSide(width: 1, color: Colors.white),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.zero,
                          borderSide: BorderSide(width: 1, color: Colors.white),
                        ),
                      ),
                      maxLines: 5,
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return '*Required';
                        }
                        return null;
                      },
                    ),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  SizedBox(
                    height: 45,
                    width: 100,
                    child: TextButton(
                      style: Btn_Submit(),
                      onPressed: () async {
                        if (_formKey.currentState!.validate()) {
                          final response = await SendEmail(
                              nameController.value.text,
                              phoneController.value.text,
                              emailController.value.text,
                              messageController.value.text);
                          ScaffoldMessenger.of(context).showSnackBar(
                            response == 200
                                ? const SnackBar(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
262 263
                                    content: Text('Message Sent!'),
                                    backgroundColor: Colors.green)
r.manan@eksad.com's avatar
r.manan@eksad.com committed
264
                                : const SnackBar(
r.manan@eksad.com's avatar
r.manan@eksad.com committed
265 266
                                    content: Text('Failed to send message!'),
                                    backgroundColor: Colors.red),
r.manan@eksad.com's avatar
r.manan@eksad.com committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
                          );

                          nameController.clear();
                          phoneController.clear();
                          emailController.clear();
                          messageController.clear();
                        }
                      },
                      child: const Text(
                        'Submit',
                        style: TextStyle(fontSize: 16, color: Colors.white),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          const Spacer(
            flex: 3,
          ),
        ],
      ),
    );
  }

  Future SendEmail(
      String name, String phone, String email, String message) async {
    final url = Uri.parse('https://api.emailjs.com/api/v1.0/email/send');
    const serviceId = 'service_wava70j';
    const templateId = 'template_koc73cj';
    const userId = 'h4BmDnyWlm3OziBDx';
    final response = await http.post(url,
        headers: {
          'Content-Type': 'application/json'
        }, //This line makes sure it works for all platforms.
        body: json.encode({
          'service_id': serviceId,
          'template_id': templateId,
          'user_id': userId,
          'template_params': {
            'from_name': name,
            'from_phone': phone,
            'to_email': email,
            'message': message
          }
        }));
    return response.statusCode;
  }
}