import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:vasthram/Constants.dart';
import 'package:vasthram/Identifyproduct.dart';
import 'package:vasthram/Identifystylecode.dart';
import 'package:vasthram/Searchbybarcode.dart';
import 'package:vasthram/SignUp.dart';
import 'package:vasthram/Uploadstylecode.dart';

class Home extends StatefulWidget {
  const Home({super.key});
  @override
  State<StatefulWidget> createState() => _Home();
}

class _Home extends State<Home> {
  File? imagefile;
  late List<File> arraylist = [];
  XFile? image;
  bool isloading = false;
  bool isVisible = true;
  bool isData = false;
  String? graph;
  String? graph1;
  Uint8List? bytes;
  Uint8List? bytes1;
  var bodycolor = '';
  var bodydesigncolor = '';
  var bordercolor = '';
  var bordersize = '';
  var borderworkcolor = '';
  var stylecode = '';
  var status = '';
  int similarsale = 0;
  int similarstock = 0;
  List<Widget> pages = [];
  Uint8List? imageBytes;
  List<dynamic>? embedding;
  String? locationMessage;

  // void getImage(File? imagefile) {
  //   final imageData = File(imagefile!.path).readAsBytesSync();
  //   final image = img.decodeImage(imageData);
  //   final imageInput = img.copyResize(
  //     image!,
  //     width: 300,
  //     height: 300,
  //   );
  //   if (kDebugMode) {
  //     print(imageInput);
  //   }
  //   final imageMatrix = List.generate(
  //     imageInput.height,
  //     (y) => List.generate(
  //       imageInput.width,
  //       (x) {
  //         final pixel = imageInput.getPixel(x, y);
  //         final r = img.getRed(pixel);
  //         final g = img.getGreen(pixel);
  //         final b = img.getBlue(pixel);
  //         return [r, g, b];
  //       },
  //     ),
  //   );
  //   embedding = imageMatrix;
  //   if (kDebugMode) {
  //     print(imageMatrix);
  //   }
  // }

  @override
  void initState() {
    super.initState();
    //_getCurrentLocation();
  }

  @override
  void dispose() {
    super.dispose();
  }

  Widget buildPage1(String title) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          if (bodycolor.isNotEmpty ||
              bodydesigncolor.isNotEmpty ||
              bordercolor.isNotEmpty ||
              bordersize.isNotEmpty ||
              borderworkcolor.isNotEmpty)
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment
                              .end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              '\tBODY COLOR: \t',
                              style: TextStyle(
                                fontSize: 15,
                                color: Colors.white,
                              ),
                              textAlign: TextAlign.right,
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              bodycolor,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),

                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment
                              .end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              'BODY DESIGN COLOR: ',
                              style: TextStyle(
                                fontSize: 15,
                                color: Colors.white,
                              ),
                              textAlign: TextAlign.right,
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              bodydesigncolor,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),

                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment
                              .end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              'BORDER COLOR: ',
                              style: TextStyle(
                                fontSize: 15,
                                color: Colors.white,
                              ),
                              textAlign: TextAlign.right,
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              bordercolor,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment.end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              'BORDER WORK COLOR: ',
                              style: TextStyle(
                                fontSize: 14,
                                color: Colors.white,
                              ),
                              textAlign: TextAlign.right,
                              softWrap: true,
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              borderworkcolor,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment
                              .end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment
                              .end, // Align content to the right
                          children: [
                            Text(
                              'BORDER SIZE:',
                              style: TextStyle(
                                fontSize: 15,
                                color: Colors.white,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              bordersize,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                //stylecode.isNotEmpty
                const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 80, 59, 83),
                          borderRadius: const BorderRadius.only(
                            topLeft: Radius.circular(20),
                            bottomLeft: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: const Column(
                          mainAxisAlignment: MainAxisAlignment
                              .end, // Align content at the bottom
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              'STYLE CODE: ',
                              style: TextStyle(
                                fontSize: 15,
                                color: Colors.white,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        decoration: BoxDecoration(
                          color: const Color.fromARGB(255, 255, 255, 255),
                          borderRadius: const BorderRadius.only(
                            topRight: Radius.circular(20),
                            bottomRight: Radius.circular(20),
                          ),
                          border: Border.all(
                            color: Colors.white, // Set border color to white
                            width: 1, // Set border width
                          ),
                        ),
                        padding: const EdgeInsets.all(12),
                        child: Column(
                          children: [
                            Text(
                              stylecode,
                              style: const TextStyle(
                                fontSize: 15,
                                color: Color.fromARGB(
                                  255,
                                  140,
                                  71,
                                  86,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            )
          else
            const SizedBox(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(padding: EdgeInsets.only(bottom: 20)),
                  Text('\n'),
                  Text('\n'),
                  Text('\n'),
                  Text('\n'),
                  Text('\n'),
                ],
              ),
            ),
        ],
      ),
    );
  }

  Widget buildPage2(String title) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 80, 59, 83),
                    borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(20),
                      bottomLeft: Radius.circular(20),
                    ),
                    border: Border.all(
                      color: Colors.white, // Set border color to white
                      width: 1, // Set border width
                    ),
                  ),
                  padding: const EdgeInsets.all(12),
                  child: const Column(
                    mainAxisAlignment:
                        MainAxisAlignment.end, // Align content at the bottom
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        'SIMILAR STOCK: ',
                        style: TextStyle(
                          fontSize: 15,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 255, 255, 255),
                    borderRadius: const BorderRadius.only(
                      topRight: Radius.circular(20),
                      bottomRight: Radius.circular(20),
                    ),
                    border: Border.all(
                      color: Colors.white, // Set border color to white
                      width: 1, // Set border width
                    ),
                  ),
                  padding: const EdgeInsets.all(12),
                  child: Column(
                    children: [
                      Text(
                        similarstock.toString(),
                        style: const TextStyle(
                          fontSize: 15,
                          color: Color.fromARGB(
                            255,
                            140,
                            71,
                            86,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          const Padding(padding: EdgeInsets.only(left: 10, top: 10)),
          Container(
            color: const Color.fromRGBO(222, 221, 220, 1),
            child: Image.memory(
              bytes!,
              fit: BoxFit.cover, // Adjust as needed
            ),
          ),
        ],
      ),
    );
  }

  Widget buildPage3(String title) {
    return Center(
        child: Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        const Padding(padding: EdgeInsets.only(left: 10, bottom: 10)),
        Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                  color: const Color.fromARGB(255, 80, 59, 83),
                  borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(20),
                    bottomLeft: Radius.circular(20),
                  ),
                  border: Border.all(
                    color: Colors.white, // Set border color to white
                    width: 1, // Set border width
                  ),
                ),
                padding: const EdgeInsets.all(12),
                child: const Column(
                  mainAxisAlignment:
                      MainAxisAlignment.end, // Align content at the bottom
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Text(
                      'SIMILAR SALE: ',
                      style: TextStyle(
                        fontSize: 15,
                        color: Colors.white,
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                  color: const Color.fromARGB(255, 255, 255, 255),
                  borderRadius: const BorderRadius.only(
                    topRight: Radius.circular(20),
                    bottomRight: Radius.circular(20),
                  ),
                  border: Border.all(
                    color: Colors.white, // Set border color to white
                    width: 1, // Set border width
                  ),
                ),
                padding: const EdgeInsets.all(12),
                child: Column(
                  children: [
                    Text(
                      similarsale.toString(),
                      style: const TextStyle(
                        fontSize: 15,
                        color: Color.fromARGB(
                          255,
                          140,
                          71,
                          86,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
        const Padding(padding: EdgeInsets.only(left: 10, top: 10)),
        Container(
          color: const Color.fromARGB(255, 240, 200, 159),
          child: Image.memory(
            bytes1!,
            fit: BoxFit.cover, // Adjust as needed
          ),
        ),
      ],
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        title: Text(
          'HOME',
          style: Constants.colorfontStyle,
        ),
        automaticallyImplyLeading: false,
        actions: [
          IconButton(
            icon: Image.asset(
              'assets/images/signout.png',
              width: 24,
              height: 24,
            ),
            onPressed: () async {
              bool valid = await Constants.checkInternetConnectivity();
              if (valid) {
                Constants.saveLoginCredentials('', '', '', '', '', false);
                Navigator.pushReplacement(context,
                    MaterialPageRoute(builder: (context) => const SignUp()));
              } else {
                Constants('Vasthram', 'Check your internet connection')
                    .showAlertDialog(context, true);
              }
            },
          ),
        ],
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: Constants.getReturn(),
          ),
        ),
      ),
      body: Stack(
        children: [
          Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage(
                    'assets/images/bg.png'), // Path to your background image
                fit: BoxFit.cover,
              ),
            ),
          ),
          SingleChildScrollView(
            child: Container(
                margin: const EdgeInsets.fromLTRB(10, 20, 10, 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const Padding(padding: EdgeInsets.only(top: 20)),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.90,
                        child: GestureDetector(
                          onTap: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      const Identifystylecode()),
                            );
                          },
                          child: Container(
                            margin: const EdgeInsets.only(
                                left: 20, top: 0, right: 2, bottom: 0),
                            width: MediaQuery.of(context).size.width * 0.100,
                            height: MediaQuery.of(context).size.width * 0.22,
                            padding: const EdgeInsets.all(5),
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                begin: Alignment.bottomLeft,
                                end: Alignment.bottomRight,
                                colors: [
                                  Color.fromARGB(255, 227, 144, 214),
                                  //Color(0xFFC2185B),
                                  Color.fromARGB(255, 125, 174, 251),
                                ],
                              ),
                              borderRadius: BorderRadius.circular(10),
                            ),
                            child: Row(
                              children: [
                                const Text('\t\t\t\t\t\t'),
                                Image.asset(
                                  'assets/images/identify.png',
                                  width: 42,
                                  height: 42,
                                ), // replace with your image

                                const Text(
                                  '\t\t\t\t\t\t IDENTIFY STYLE CODE',
                                  style: Constants.buttonsfontStyle,
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    ]),
                    const Padding(padding: EdgeInsets.only(top: 20)),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.90,
                        child: GestureDetector(
                          onTap: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      const Uploadstylecode()),
                            );
                          },
                          child: Container(
                            margin: const EdgeInsets.only(
                                left: 20, top: 0, right: 2, bottom: 0),
                            width: MediaQuery.of(context).size.width * 0.100,
                            height: MediaQuery.of(context).size.width * 0.22,
                            padding: const EdgeInsets.all(5),
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                begin: Alignment.bottomLeft,
                                end: Alignment.bottomRight,
                                colors: [
                                  Color.fromARGB(255, 244, 244, 254),
                                  Color.fromARGB(255, 244, 244, 254),
                                ],
                              ),
                              borderRadius: BorderRadius.circular(7),
                              border: Border.all(
                                color: const Color.fromARGB(255, 255, 255,
                                    255), // Your desired border color
                                width: 2, // Border width
                              ),
                            ),
                            child: Row(
                              children: [
                                const Text('\t\t\t\t\t\t'),
                                Image.asset(
                                  'assets/images/register.png',
                                  width: 42,
                                  height: 42,
                                ),
                                const Text(
                                  '\t\t\t\t\t REGISTER STYLE CODE',
                                  style: Constants.loginfontStyle,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ]),
                    const Padding(padding: EdgeInsets.only(top: 20)),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.90,
                        child: GestureDetector(
                          onTap: () {
                            Navigator.push(context,
                             MaterialPageRoute(
                               builder: (context) =>
                                const Identifyproduct()),
                            );
                          },
                          child: Container(
                            margin: const EdgeInsets.only(left: 20, top: 0, right: 2, bottom: 0),
                            width: MediaQuery.of(context).size.width * 0.100,
                            height: MediaQuery.of(context).size.width * 0.22,
                            padding: const EdgeInsets.all(5),
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                begin: Alignment.bottomLeft,
                                end: Alignment.bottomRight,
                                colors: [
                                  Color.fromARGB(255, 227, 144, 214),
                                  Color.fromARGB(255, 125, 174, 251),
                                ],
                              ),
                              borderRadius: BorderRadius.circular(10),
                            ),
                            child: Row(
                              children: [
                                const Text('\t\t\t\t\t\t'),
                                Image.asset(
                                  'assets/images/identify_product.png',
                                  width: 42,
                                  height: 42,
                                ), // replace with your image
                                const Text(
                                  '\t\t\t\t\t\t DETECT ATTRIBUTES',
                                  style: Constants.buttonsfontStyle,
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    ]),
                    const Padding(padding: EdgeInsets.only(top: 20)),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.90,
                        child: GestureDetector(
                          onTap: () {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      const Searchbybarcode()),
                            );
                          },
                          child: Container(
                            margin: const EdgeInsets.only(
                                left: 20, top: 0, right: 2, bottom: 0),
                            width: MediaQuery.of(context).size.width * 0.100,
                            height: MediaQuery.of(context).size.width * 0.22,
                            padding: const EdgeInsets.all(5),
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                begin: Alignment.bottomLeft,
                                end: Alignment.bottomRight,
                                colors: [
                                  Color.fromARGB(255, 244, 244, 254),
                                  //Color(0xFFC2185B),
                                  Color.fromARGB(255, 244, 244, 254),
                                ],
                              ),
                              borderRadius: BorderRadius.circular(7),
                              border: Border.all(
                                color: const Color.fromARGB(255, 255, 255,
                                    255), // Your desired border color
                                width: 2, // Border width
                              ),
                            ),
                            child: Row(
                              children: [
                                const Text('\t\t\t\t\t\t'),
                                Image.asset(
                                  'assets/images/search.png',
                                  width: 42,
                                  height: 42,
                                ),
                                // replace with your image
                                const Text(
                                  '\t\t\t\t\t SEARCH BY BARCODE',
                                  style: Constants.loginfontStyle,
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ]),
                  ],
                )),
          ),
        ],
      ),
    );
  }

  void updateUI(Map<String, dynamic> jsonResponse) {
    setState(() {
      isData = true;
      isloading = false;
      isVisible = false;
      status = jsonResponse['status'];
      if (status == 'Success') {
        bodycolor = jsonResponse['body_color'];
        bodydesigncolor = jsonResponse['body_design_color'];
        bordercolor = jsonResponse['border_color'];
        bordersize = jsonResponse['border_size'];
        borderworkcolor = jsonResponse['border_design_color'];
        stylecode = jsonResponse['stylecode'];
        similarsale = jsonResponse['similarsale'];
        similarstock = jsonResponse['similarstock'];
        bytes = base64.decode(jsonResponse['similarstockgraph']);
        bytes1 = base64.decode(jsonResponse['similarsalegraph']);
      } else {
        Constants.dialogMessage(context, 'Vasthram', 'Could not found image');
        bodycolor = '';
        bodydesigncolor = '';
        bordercolor = '';
        bordersize = '';
        borderworkcolor = '';
        stylecode = '';
        bytes!.clear();
        bytes1!.clear();
        embedding!.clear();
      }
    });
  }
}
