|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_code/src/objects/facility.dart'; |
| 3 | +import 'package:flutter_code/src/server_comm/authentication.dart'; |
| 4 | +import 'package:flutter_code/src/views/facility_view.dart'; |
| 5 | +import 'src/server_comm/requests.dart'; |
| 6 | +import 'package:geolocator/geolocator.dart'; |
| 7 | +import 'package:geocoding/geocoding.dart'; |
| 8 | + |
| 9 | +void main() => runApp(const MyApp()); |
| 10 | + |
| 11 | +class MyApp extends StatelessWidget { |
| 12 | + const MyApp({Key? key}) : super(key: key); |
| 13 | + |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + return MaterialApp( |
| 17 | + title: 'FEUPQ', |
| 18 | + theme: ThemeData(primarySwatch: Colors.deepOrange), |
| 19 | + home: const HomeView(), |
| 20 | + ); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +// Filter makes it so the Widget is Stateful |
| 25 | +class HomeView extends StatefulWidget { |
| 26 | + final String? authToken; |
| 27 | + const HomeView({Key? key, this.authToken}) : super(key: key); |
| 28 | + |
| 29 | + @override |
| 30 | + State<HomeView> createState() => _HomeViewState(); |
| 31 | +} |
| 32 | + |
| 33 | +class _HomeViewState extends State<HomeView> { |
| 34 | + final List<Facility> __facility = getFacilitiesList(); |
| 35 | + late List<Facility> facility; |
| 36 | + @override |
| 37 | + void initState() { |
| 38 | + super.initState(); |
| 39 | + facility = __facility; |
| 40 | + } |
| 41 | + |
| 42 | + // var nearestFacility = getNearestFacility(); |
| 43 | + // facility.remove(nearestFacility); |
| 44 | + // facility.insert(0, nearestFacility); |
| 45 | + @override |
| 46 | + Widget build(BuildContext context) { |
| 47 | + return Scaffold( |
| 48 | + appBar: AppBar( |
| 49 | + title: const Center( |
| 50 | + child: Text('FEUPQ'), |
| 51 | + ), |
| 52 | + ), |
| 53 | + body: Column(children: [ |
| 54 | + FutureBuilder<Facility>( |
| 55 | + future: getNearestFacility(facility), |
| 56 | + builder: (context, snapshot) { |
| 57 | + if (snapshot.hasData) { |
| 58 | + return Column(children: [ |
| 59 | + Text("Fila mais perto:",style: const TextStyle(height: 3, fontSize: 20)), |
| 60 | + Card( |
| 61 | + child: ListTile( |
| 62 | + title: Text(snapshot.data!.name), |
| 63 | + onTap: () { |
| 64 | + Navigator.of(context).push(MaterialPageRoute( |
| 65 | + builder: (context) => FacilityView( |
| 66 | + facility: facility[snapshot.data!.id], |
| 67 | + ))); |
| 68 | + }), |
| 69 | + ) |
| 70 | + ]); |
| 71 | + } else { |
| 72 | + return Text("Não há fila mais proxima",style: const TextStyle(height: 3, fontSize: 20)); |
| 73 | + } |
| 74 | + }), |
| 75 | + Text("Todas as Filas: ",style: const TextStyle(height: 3, fontSize: 20)), |
| 76 | + Padding( |
| 77 | + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), |
| 78 | + child: TextField( |
| 79 | + key: const ValueKey("searchBar"), |
| 80 | + onChanged: (text) { |
| 81 | + setState(() { |
| 82 | + if (text == "") { |
| 83 | + facility = __facility; |
| 84 | + } else { |
| 85 | + facility = __facility |
| 86 | + .where((facility) => facility.name |
| 87 | + .toLowerCase() |
| 88 | + .contains(text.toLowerCase())) |
| 89 | + .toList(); |
| 90 | + } |
| 91 | + }); |
| 92 | + }, |
| 93 | + decoration: const InputDecoration( |
| 94 | + border: OutlineInputBorder(), |
| 95 | + hintText: 'Barra de Pesquisa', |
| 96 | + ), |
| 97 | + ), |
| 98 | + ), |
| 99 | + ListView.builder( |
| 100 | + itemCount: facility.length, |
| 101 | + itemBuilder: (context, index) { |
| 102 | + return Card( |
| 103 | + child: ListTile( |
| 104 | + title: Text(facility[index].name), |
| 105 | + onTap: () { |
| 106 | + Navigator.of(context).push(MaterialPageRoute( |
| 107 | + builder: (context) => FacilityView( |
| 108 | + facility: facility[index], |
| 109 | + ))); |
| 110 | + }), |
| 111 | + ); |
| 112 | + }, |
| 113 | + shrinkWrap: true, |
| 114 | + ), |
| 115 | + ]), |
| 116 | + ); |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +class LoginView extends StatefulWidget { |
| 121 | + const LoginView({Key? key}) : super(key: key); |
| 122 | + |
| 123 | + @override |
| 124 | + LoginViewState createState() => LoginViewState(); |
| 125 | +} |
| 126 | + |
| 127 | +class LoginViewState extends State<LoginView> { |
| 128 | + bool visible = true; |
| 129 | + |
| 130 | + @override |
| 131 | + Widget build(BuildContext context) { |
| 132 | + return Scaffold( |
| 133 | + appBar: AppBar( |
| 134 | + title: const Center( |
| 135 | + child: Text('FEUPQ'), |
| 136 | + ), |
| 137 | + ), |
| 138 | + body: Column( |
| 139 | + children: [ |
| 140 | + Padding( |
| 141 | + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), |
| 142 | + child: TextFormField( |
| 143 | + obscureText: true, |
| 144 | + decoration: const InputDecoration( |
| 145 | + border: UnderlineInputBorder(), |
| 146 | + labelText: 'Enter your username', |
| 147 | + ), |
| 148 | + ), |
| 149 | + ), |
| 150 | + Padding( |
| 151 | + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), |
| 152 | + child: TextFormField( |
| 153 | + obscureText: visible, |
| 154 | + decoration: InputDecoration( |
| 155 | + border: const UnderlineInputBorder(), |
| 156 | + labelText: 'Enter your password', |
| 157 | + suffix: InkWell( |
| 158 | + onTap: changePasswordVisibilityState, |
| 159 | + child: Icon( |
| 160 | + visible ? Icons.visibility : Icons.visibility_off, |
| 161 | + ), |
| 162 | + )), |
| 163 | + ), |
| 164 | + ), |
| 165 | + ElevatedButton( |
| 166 | + child: const Text( |
| 167 | + 'Login/Register', |
| 168 | + textAlign: TextAlign.center, |
| 169 | + ), |
| 170 | + onPressed: () { |
| 171 | + Navigator.push( |
| 172 | + context, |
| 173 | + MaterialPageRoute( |
| 174 | + builder: (context) => |
| 175 | + HomeView(authToken: logIn("user", "pass"))), |
| 176 | + ); |
| 177 | + }, |
| 178 | + ) |
| 179 | + ], |
| 180 | + )); |
| 181 | + } |
| 182 | + |
| 183 | + void changePasswordVisibilityState() { |
| 184 | + setState(() { |
| 185 | + visible = !visible; |
| 186 | + }); |
| 187 | + } |
| 188 | +} |
0 commit comments