|
| 1 | +import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | +import 'package:dio/dio.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:onestop_dev/globals/my_colors.dart'; |
| 5 | +import 'package:onestop_dev/globals/my_fonts.dart'; |
| 6 | + |
| 7 | +import '../../widgets/ui/list_shimmer.dart'; |
| 8 | + |
| 9 | +class VoterCard extends StatefulWidget { |
| 10 | + final String email; |
| 11 | + final String authCookie; |
| 12 | + |
| 13 | + const VoterCard({Key? key, required this.email, required this.authCookie}) |
| 14 | + : super(key: key); |
| 15 | + |
| 16 | + @override |
| 17 | + State<VoterCard> createState() => _VoterCardState(); |
| 18 | +} |
| 19 | + |
| 20 | +class _VoterCardState extends State<VoterCard> { |
| 21 | + Dio dio = Dio(); |
| 22 | + |
| 23 | + Map<String, String> branches = { |
| 24 | + "None": 'None', |
| 25 | + 'CSE': '01', |
| 26 | + 'ECE': '02', |
| 27 | + 'ME': '03', |
| 28 | + 'Civil': '04', |
| 29 | + 'Design': '05', |
| 30 | + 'BSBE': '06', |
| 31 | + 'CL': '07', |
| 32 | + 'EEE': '08', |
| 33 | + 'Physics': '21', |
| 34 | + 'Chemistry': '22', |
| 35 | + 'MNC': '23', |
| 36 | + 'HSS': '41', |
| 37 | + 'Energy': '51', |
| 38 | + 'Environment': '52', |
| 39 | + 'Nano-Tech': '53', |
| 40 | + 'Rural-Tech': '54', |
| 41 | + 'Linguistics': '55', |
| 42 | + 'Others': '61', |
| 43 | + }; |
| 44 | + |
| 45 | + Map<String, String> degrees = { |
| 46 | + "B.Tech": "B", |
| 47 | + "M.Tech": "M", |
| 48 | + "PhD": "P", |
| 49 | + "MSc": "Msc", |
| 50 | + "Bdes": "Bdes", |
| 51 | + "Mdes": "Mdes", |
| 52 | + "Dual Degree": "Dual", |
| 53 | + "MA": "MA", |
| 54 | + "MSR": "MSR", |
| 55 | + "MBA": "MBA", |
| 56 | + "Others": "Others" |
| 57 | + }; |
| 58 | + |
| 59 | + String getBranch(String input) { |
| 60 | + String answer = "Others"; |
| 61 | + for (var key in branches.keys) { |
| 62 | + if (branches[key] == input) { |
| 63 | + return key; |
| 64 | + } |
| 65 | + } |
| 66 | + return answer; |
| 67 | + } |
| 68 | + |
| 69 | + String getDegree(String input) { |
| 70 | + String answer = "B.Tech"; |
| 71 | + for (var key in degrees.keys) { |
| 72 | + if (degrees[key] == input) { |
| 73 | + return key; |
| 74 | + } |
| 75 | + } |
| 76 | + return answer; |
| 77 | + } |
| 78 | + |
| 79 | + @override |
| 80 | + Widget build(BuildContext context) { |
| 81 | + dio.options.headers['cookie'] = |
| 82 | + widget.authCookie; // setting cookies for auth |
| 83 | + dio.post("https://swc.iitg.ac.in/elections_api/sgc/voting/get_eprofile/", |
| 84 | + data: {"email": widget.email}).then((value) { |
| 85 | + //print(value); |
| 86 | + }); |
| 87 | + return FutureBuilder<Response>( |
| 88 | + future: dio.post( |
| 89 | + "https://swc.iitg.ac.in/elections_api/sgc/voting/get_eprofile/", |
| 90 | + data: {"email": widget.email}), |
| 91 | + builder: (context, snapshot) { |
| 92 | + if (!snapshot.hasData || snapshot.hasError) { |
| 93 | + return Center( |
| 94 | + child: ListShimmer( |
| 95 | + count: 1, |
| 96 | + height: 750, |
| 97 | + )); |
| 98 | + } |
| 99 | + //print(snapshot.data!); |
| 100 | + var data = snapshot.data!.data; |
| 101 | + //print(data); |
| 102 | + return Column( |
| 103 | + mainAxisSize: MainAxisSize.min, |
| 104 | + children: [ |
| 105 | + const SizedBox( |
| 106 | + height: 15, |
| 107 | + ), |
| 108 | + Expanded( |
| 109 | + child: SingleChildScrollView( |
| 110 | + child: Column( |
| 111 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 112 | + children: [ |
| 113 | + Row( |
| 114 | + children: [ |
| 115 | + Expanded( |
| 116 | + child: Container( |
| 117 | + alignment: Alignment.center, |
| 118 | + child: Text( |
| 119 | + "IITG GYMKHANA ELECTIONS 2023", |
| 120 | + style: |
| 121 | + MyFonts.w700.setColor(kWhite).size(25), |
| 122 | + textAlign: TextAlign.center, |
| 123 | + ))), |
| 124 | + ], |
| 125 | + ), |
| 126 | + Text( |
| 127 | + "Voter ID", |
| 128 | + style: MyFonts.w500.setColor(kWhite).size(25), |
| 129 | + ), |
| 130 | + const SizedBox( |
| 131 | + height: 25, |
| 132 | + ), |
| 133 | + Container( |
| 134 | + height: 200, |
| 135 | + width: 200, |
| 136 | + decoration: const BoxDecoration( |
| 137 | + shape: BoxShape.rectangle, |
| 138 | + ), |
| 139 | + child: CachedNetworkImage( |
| 140 | + imageUrl: data["img_url"], |
| 141 | + placeholder: (context, url) => ListShimmer( |
| 142 | + count: 1, |
| 143 | + height: 200, |
| 144 | + ), |
| 145 | + errorWidget: (context, url, error) => const Image( |
| 146 | + image: NetworkImage( |
| 147 | + 'https://t4.ftcdn.net/jpg/03/46/93/61/360_F_346936114_RaxE6OQogebgAWTalE1myseY1Hbb5qPM.jpg')), |
| 148 | + ), |
| 149 | + ), |
| 150 | + const SizedBox( |
| 151 | + height: 15, |
| 152 | + ), |
| 153 | + //Image.network('src'), |
| 154 | + Padding( |
| 155 | + padding: const EdgeInsets.all(8.0), |
| 156 | + child: Text( |
| 157 | + "Name: ${data["name"]}", |
| 158 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 159 | + textAlign: TextAlign.center, |
| 160 | + ), |
| 161 | + ), |
| 162 | + Padding( |
| 163 | + padding: const EdgeInsets.all(8.0), |
| 164 | + child: Text( |
| 165 | + "Roll no: ${data["roll_no"]}", |
| 166 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 167 | + textAlign: TextAlign.center, |
| 168 | + ), |
| 169 | + ), |
| 170 | + Padding( |
| 171 | + padding: const EdgeInsets.all(8.0), |
| 172 | + child: Text( |
| 173 | + "Degree: ${getDegree(data['degree'])}", |
| 174 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 175 | + textAlign: TextAlign.center, |
| 176 | + ), |
| 177 | + ), |
| 178 | + Padding( |
| 179 | + padding: const EdgeInsets.all(8.0), |
| 180 | + child: Text( |
| 181 | + "Hostel: ${data['hostel'][0].toString().toUpperCase()}${data['hostel'].toString().substring(1)}", |
| 182 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 183 | + textAlign: TextAlign.center, |
| 184 | + ), |
| 185 | + ), |
| 186 | + Padding( |
| 187 | + padding: const EdgeInsets.all(8.0), |
| 188 | + child: Text( |
| 189 | + "Branch: ${getBranch(data['branch'])}", |
| 190 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 191 | + textAlign: TextAlign.center, |
| 192 | + ), |
| 193 | + ), |
| 194 | + Padding( |
| 195 | + padding: const EdgeInsets.all(8.0), |
| 196 | + child: Text( |
| 197 | + "Gender: ${data["gender"]}", |
| 198 | + style: MyFonts.w500.setColor(kWhite).size(18), |
| 199 | + textAlign: TextAlign.center, |
| 200 | + ), |
| 201 | + ), |
| 202 | + ], |
| 203 | + ), |
| 204 | + ), |
| 205 | + ), |
| 206 | + Text( |
| 207 | + 'Made by', |
| 208 | + style: MyFonts.w600.setColor(kWhite).size(10), |
| 209 | + ), |
| 210 | + const SizedBox( |
| 211 | + height: 5, |
| 212 | + ), |
| 213 | + SizedBox( |
| 214 | + height: 25, |
| 215 | + child: Image.asset( |
| 216 | + 'assets/images/logoo.png', |
| 217 | + cacheWidth: 451, |
| 218 | + cacheHeight: 75, |
| 219 | + )), |
| 220 | + const SizedBox( |
| 221 | + height: 15, |
| 222 | + ) |
| 223 | + ], |
| 224 | + ); |
| 225 | + }); |
| 226 | + } |
| 227 | +} |
0 commit comments