Commit 2a6f420b authored by Shoaib's avatar Shoaib
Browse files

Work in progress.

No related merge requests found
Showing with 666 additions and 435 deletions
+666 -435
l10n.yaml 0 → 100644
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
\ No newline at end of file
...@@ -4,4 +4,6 @@ class ApiUrl { ...@@ -4,4 +4,6 @@ class ApiUrl {
static const validateOtp = '$baseUrl/api/signIn'; static const validateOtp = '$baseUrl/api/signIn';
static const getAllApplications = '$baseUrl/api/forms/getAllApplications'; static const getAllApplications = '$baseUrl/api/forms/getAllApplications';
static const submitInspection = '$baseUrl/api/forms/submitInspection'; static const submitInspection = '$baseUrl/api/forms/submitInspection';
static const getAllUsers = '$baseUrl/api/user/v1/getAllUser';
static const getFormDetails = '$baseUrl/api/forms/getFormById?id=';
} }
const String appVersion = '1.0'; const String appVersion = '1.0';
const String appName = 'UP SMF'; const String appName = 'UP SMF';
const int inspectorRoleId = 2093;
// class Status { class FieldType {
// static const String active = 'active'; static const String text = "text";
// static const String completed = 'completed'; static const String date = "date";
// static const String deleted = 'deleted'; static const String email = "email";
// } static const String numeric = "numeric";
static const String textarea = "textarea";
static const String dropdown = "dropdown";
static const String multiselect = "multiselect";
static const String checkbox = "checkbox";
static const String radio = "radio";
static const String boolean = "boolean";
static const String file = "file";
static const String heading = 'heading';
}
class InspectionStatus {
static const String sentForInspection = 'SENTFORINS';
static const String inspectionCompleted = 'INSCOMPLETED';
}
{
"login": "Login",
"emailId": "Email Id",
"getOtp": "GET OTP",
"enterOtp": "Enter OTP",
"otpFieldDescription": "Enter the 6 digit OTP sent to your email address.",
"signIn": "SIGN IN",
"goBackText": "Go back, re-enter the email",
"pendingApplications": "Pending applications",
"today": "Today",
"upcoming": "Upcoming",
"pastApplications": "Past applications",
"viewPastApplications": "View past applications",
"next": "Next",
"previous": "previous",
"inspectionCompleted": "Inspection completed"
}
\ No newline at end of file
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smf_mobile/pages/home_page.dart'; import 'package:smf_mobile/pages/home_page.dart';
import 'package:smf_mobile/pages/login_email_page.dart'; import 'package:smf_mobile/pages/login_email_page.dart';
import 'package:smf_mobile/repositories/application_repository.dart'; import 'package:smf_mobile/repositories/application_repository.dart';
import 'package:smf_mobile/repositories/form_repository.dart';
import 'package:smf_mobile/repositories/login_repository.dart'; import 'package:smf_mobile/repositories/login_repository.dart';
import 'package:smf_mobile/repositories/user_repository.dart';
import 'constants/app_constants.dart'; import 'constants/app_constants.dart';
import 'constants/app_urls.dart'; import 'constants/app_urls.dart';
import 'constants/color_constants.dart'; import 'constants/color_constants.dart';
import 'routes.dart'; import 'routes.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LandingPage extends StatefulWidget { class LandingPage extends StatefulWidget {
static const route = AppUrl.landingPage; static const route = AppUrl.landingPage;
const LandingPage({Key? key}) : super(key: key); const LandingPage({Key? key}) : super(key: key);
@override @override
_LandingPageState createState() => _LandingPageState(); _LandingPageState createState() => _LandingPageState();
static _LandingPageState? of(BuildContext context) =>
context.findAncestorStateOfType<_LandingPageState>();
} }
class _LandingPageState extends State<LandingPage> { class _LandingPageState extends State<LandingPage> {
final client = HttpClient(); final client = HttpClient();
Locale _locale = const Locale('en', 'US');
void setLocale(Locale value) {
setState(() {
_locale = value;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -27,9 +41,22 @@ class _LandingPageState extends State<LandingPage> { ...@@ -27,9 +41,22 @@ class _LandingPageState extends State<LandingPage> {
providers: [ providers: [
ChangeNotifierProvider.value(value: LoginRespository()), ChangeNotifierProvider.value(value: LoginRespository()),
ChangeNotifierProvider.value(value: ApplicationRespository()), ChangeNotifierProvider.value(value: ApplicationRespository()),
ChangeNotifierProvider.value(value: UserRespository()),
ChangeNotifierProvider.value(value: FormRespository()),
], ],
child: MaterialApp( child: MaterialApp(
title: appName, title: appName,
locale: _locale,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', 'US'),
// Locale('es', 'ES'),
],
theme: ThemeData( theme: ThemeData(
scaffoldBackgroundColor: AppColors.scaffoldBackground, scaffoldBackgroundColor: AppColors.scaffoldBackground,
primaryColor: Colors.white, primaryColor: Colors.white,
......
...@@ -8,6 +8,7 @@ class Application { ...@@ -8,6 +8,7 @@ class Application {
final String status; final String status;
final Map dataObject; final Map dataObject;
final List inspectors; final List inspectors;
final List leadInspector;
final String scheduledDate; final String scheduledDate;
final String createdDate; final String createdDate;
final String createdBy; final String createdBy;
...@@ -20,6 +21,7 @@ class Application { ...@@ -20,6 +21,7 @@ class Application {
required this.status, required this.status,
required this.dataObject, required this.dataObject,
required this.inspectors, required this.inspectors,
required this.leadInspector,
required this.scheduledDate, required this.scheduledDate,
required this.createdDate, required this.createdDate,
required this.createdBy, required this.createdBy,
...@@ -34,6 +36,7 @@ class Application { ...@@ -34,6 +36,7 @@ class Application {
status: json['status'], status: json['status'],
dataObject: json['dataObject'], dataObject: json['dataObject'],
inspectors: json['inspection']['assignedTo'] ?? [], inspectors: json['inspection']['assignedTo'] ?? [],
leadInspector: json['inspection']['leadInspector'] ?? [],
scheduledDate: json['inspection']['scheduledDate'] ?? '', scheduledDate: json['inspection']['scheduledDate'] ?? '',
createdDate: json['createdDate'] != null createdDate: json['createdDate'] != null
? DateFormat.yMMMEd().format(DateTime.parse(json['createdDate'])) ? DateFormat.yMMMEd().format(DateTime.parse(json['createdDate']))
...@@ -50,6 +53,7 @@ class Application { ...@@ -50,6 +53,7 @@ class Application {
status, status,
dataObject, dataObject,
inspectors, inspectors,
leadInspector,
scheduledDate, scheduledDate,
createdDate, createdDate,
createdBy createdBy
......
class FormData {
final int id;
final int version;
final String title;
final String description;
final List<dynamic> fields;
final List<dynamic> inspectionFields;
final int updatedDate;
const FormData({
required this.id,
required this.version,
required this.title,
required this.description,
required this.fields,
required this.inspectionFields,
required this.updatedDate,
});
factory FormData.fromJson(Map<String, dynamic> json) {
return FormData(
id: json['id'],
version: json['version'],
title: json['title'],
description: json['description'],
fields: json['fields'] ?? [],
inspectionFields: json['inspectionFields'] ?? [],
updatedDate: json['updatedDate']);
}
List<Object> get props => [
id,
version,
title,
description,
fields,
inspectionFields,
updatedDate,
];
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smf_mobile/constants/app_constants.dart';
import 'package:smf_mobile/constants/color_constants.dart'; import 'package:smf_mobile/constants/color_constants.dart';
import 'package:smf_mobile/models/application_model.dart';
import 'package:smf_mobile/models/form_model.dart';
import 'package:smf_mobile/pages/inspection_summary.dart'; import 'package:smf_mobile/pages/inspection_summary.dart';
import 'package:smf_mobile/pages/login_email_page.dart'; import 'package:smf_mobile/pages/login_email_page.dart';
import 'package:smf_mobile/repositories/application_repository.dart'; import 'package:smf_mobile/repositories/form_repository.dart';
import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/util/helper.dart';
import 'package:smf_mobile/widgets/application_field.dart'; import 'package:smf_mobile/widgets/application_field.dart';
import 'package:smf_mobile/widgets/silverappbar_delegate.dart'; import 'package:smf_mobile/widgets/silverappbar_delegate.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ApplicationDetailsPage extends StatefulWidget { class ApplicationDetailsPage extends StatefulWidget {
final String applicationId; final Application application;
final String applicationTitle;
final Map applicationFields;
final List applicationInspectors;
const ApplicationDetailsPage({ const ApplicationDetailsPage({
Key? key, Key? key,
required this.applicationId, required this.application,
required this.applicationTitle,
required this.applicationFields,
required this.applicationInspectors,
}) : super(key: key); }) : super(key: key);
@override @override
...@@ -30,30 +28,53 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -30,30 +28,53 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
TabController? _tabController; TabController? _tabController;
late FormData _formData;
int _activeTabIndex = 0; int _activeTabIndex = 0;
final Map _data = {}; final Map _data = {};
final Map _fieldTypes = {};
final List<String> _tabs = []; final List<String> _tabs = [];
final List<Map> _fields = []; final List<Map> _fields = [];
String _errorMessage = '';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
widget.applicationFields.forEach((key, value) => _tabs.add(key));
widget.application.dataObject.forEach((key, value) => _tabs.add(key));
_tabController = TabController(vsync: this, length: _tabs.length); _tabController = TabController(vsync: this, length: _tabs.length);
_tabController!.addListener(_setActiveTabIndex); _tabController!.addListener(_setActiveTabIndex);
_populateFields(); _populateFields();
} }
Future<dynamic> _getFormDetails() async {
_validateUser();
_formData = await Provider.of<FormRespository>(context, listen: false)
.getFormDetails(widget.application.formId);
// print('object');
String _errorMessage =
Provider.of<FormRespository>(context, listen: false).errorMessage;
if (_errorMessage != '') {
Helper.toastMessage(_errorMessage);
} else {
for (int i = 0; i < _formData.fields.length; i++) {
if (_formData.fields[i]['fieldType'] != FieldType.heading) {
_fieldTypes[_formData.fields[i]['name']] =
_formData.fields[i]['fieldType'];
}
}
}
// print(_fieldTypes);
return _fieldTypes;
}
void _setActiveTabIndex() { void _setActiveTabIndex() {
setState(() { setState(() {
_activeTabIndex = _tabController!.index; _activeTabIndex = _tabController!.index;
}); });
} }
void _populateFields() { void _populateFields() async {
Map updatedFields = {}; Map updatedFields = {};
widget.applicationFields.forEach((key, value) => { widget.application.dataObject.forEach((key, value) => {
updatedFields = {}, updatedFields = {},
value.forEach((childKey, childValue) => { value.forEach((childKey, childValue) => {
updatedFields[childKey] = { updatedFields[childKey] = {
...@@ -91,24 +112,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -91,24 +112,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
Future<void> _submitInspection() async { Future<void> _submitInspection() async {
_validateUser(); _validateUser();
Map data = {'applicationId': widget.applicationId, 'dataObject': _data}; Map data = {
try { 'applicationId': widget.application.applicationId,
final responseCode = 'dataObject': _data
await Provider.of<ApplicationRespository>(context, listen: false) };
.submitInspection(data);
if (responseCode == 200) { Navigator.of(context).pushReplacement(MaterialPageRoute(
Navigator.of(context).pushReplacement(MaterialPageRoute( builder: (context) => InspectionSummaryPage(
builder: (context) => InspectionSummaryPage( // formId: widget.formId,
inspectors: widget.applicationInspectors))); formId: 1645422297511,
} else { inspectors: widget.application.inspectors,
_errorMessage = leadInspector: widget.application.leadInspector,
Provider.of<ApplicationRespository>(context, listen: false) inspectionData: data,
.errorMessage; )));
Helper.toastMessage(_errorMessage);
}
} catch (err) {
throw Exception(err);
}
} }
@override @override
...@@ -128,7 +144,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -128,7 +144,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
backgroundColor: Colors.white, backgroundColor: Colors.white,
leading: const BackButton(color: AppColors.black60), leading: const BackButton(color: AppColors.black60),
title: Text( title: Text(
widget.applicationTitle, widget.application.title,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
fontSize: 16.0, fontSize: 16.0,
...@@ -201,24 +217,43 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -201,24 +217,43 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
), ),
]; ];
}, },
body: Container( body: FutureBuilder(
padding: const EdgeInsets.only(top: 20), future: _getFormDetails(),
color: AppColors.scaffoldBackground, builder: (context, AsyncSnapshot<dynamic> snapshot) {
child: if (snapshot.hasData && snapshot.data != null) {
TabBarView(controller: _tabController, children: [ return Container(
for (Map field in _fields) padding: const EdgeInsets.only(top: 20),
ListView.builder( color: AppColors.scaffoldBackground,
shrinkWrap: true, child: TabBarView(
physics: const NeverScrollableScrollPhysics(), controller: _tabController,
itemCount: field.length, children: [
itemBuilder: (context, i) { for (Map field in _fields)
return ApplicationField( ListView.builder(
fieldName: field.keys.elementAt(i), shrinkWrap: true,
fieldData: field[field.keys.elementAt(i)], physics:
parentAction: updateField, const NeverScrollableScrollPhysics(),
); itemCount: field.length,
}) itemBuilder: (context, i) {
]))))), return ApplicationField(
fieldName:
field.keys.elementAt(i),
fieldData: field[
field.keys.elementAt(i)],
fieldType: _fieldTypes[
field.keys.elementAt(i)],
applicationStatus:
widget.application.status,
parentAction: updateField,
);
})
]));
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
)))),
), ),
bottomNavigationBar: BottomAppBar( bottomNavigationBar: BottomAppBar(
elevation: 20, elevation: 20,
...@@ -248,7 +283,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -248,7 +283,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
Padding( Padding(
padding: const EdgeInsets.only(left: 10), padding: const EdgeInsets.only(left: 10),
child: Text( child: Text(
'Previous', AppLocalizations.of(context)!.previous,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.primaryBlue, color: AppColors.primaryBlue,
fontSize: 14.0, fontSize: 14.0,
...@@ -268,7 +303,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -268,7 +303,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
Padding( Padding(
padding: const EdgeInsets.only(right: 10), padding: const EdgeInsets.only(right: 10),
child: Text( child: Text(
'Next', AppLocalizations.of(context)!.next,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.primaryBlue, color: AppColors.primaryBlue,
fontSize: 14.0, fontSize: 14.0,
...@@ -282,27 +317,32 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ...@@ -282,27 +317,32 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage>
) )
], ],
)) ))
: TextButton( : widget.application.status ==
onPressed: () { InspectionStatus.sentForInspection
_submitInspection(); ? TextButton(
}, onPressed: () {
style: TextButton.styleFrom( _submitInspection();
// primary: Colors.white, },
padding: const EdgeInsets.only(left: 15, right: 15), style: TextButton.styleFrom(
backgroundColor: AppColors.primaryBlue, // primary: Colors.white,
shape: RoundedRectangleBorder( padding:
borderRadius: BorderRadius.circular(4), const EdgeInsets.only(left: 15, right: 15),
side: const BorderSide(color: AppColors.black16)), backgroundColor: AppColors.primaryBlue,
), shape: RoundedRectangleBorder(
child: Text( borderRadius: BorderRadius.circular(4),
'Inspection completed', side: const BorderSide(
style: GoogleFonts.lato( color: AppColors.black16)),
color: Colors.white, ),
fontWeight: FontWeight.w700, child: Text(
fontSize: 14, AppLocalizations.of(context)!.inspectionCompleted,
), style: GoogleFonts.lato(
), color: Colors.white,
), fontWeight: FontWeight.w700,
fontSize: 14,
),
),
)
: const Center(),
], ],
), ),
)), )),
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smf_mobile/constants/app_urls.dart'; import 'package:smf_mobile/constants/app_urls.dart';
...@@ -10,6 +9,7 @@ import 'package:smf_mobile/pages/past_applications.dart'; ...@@ -10,6 +9,7 @@ import 'package:smf_mobile/pages/past_applications.dart';
import 'package:smf_mobile/repositories/application_repository.dart'; import 'package:smf_mobile/repositories/application_repository.dart';
import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/util/helper.dart';
import 'package:smf_mobile/widgets/application_card.dart'; import 'package:smf_mobile/widgets/application_card.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
// import 'dart:developer' as developer; // import 'dart:developer' as developer;
...@@ -75,6 +75,10 @@ class _HomePageState extends State<HomePage> { ...@@ -75,6 +75,10 @@ class _HomePageState extends State<HomePage> {
return _allApplications; return _allApplications;
} }
Future<void> _pullRefresh() async {
setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -84,7 +88,7 @@ class _HomePageState extends State<HomePage> { ...@@ -84,7 +88,7 @@ class _HomePageState extends State<HomePage> {
titleSpacing: 20, titleSpacing: 20,
backgroundColor: Colors.white, backgroundColor: Colors.white,
title: Text( title: Text(
'Pending applications', AppLocalizations.of(context)!.pendingApplications,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
fontSize: 16.0, fontSize: 16.0,
...@@ -95,8 +99,7 @@ class _HomePageState extends State<HomePage> { ...@@ -95,8 +99,7 @@ class _HomePageState extends State<HomePage> {
// centerTitle: true, // centerTitle: true,
), ),
// Tab controller // Tab controller
body: SingleChildScrollView( body: Container(
child: Container(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(), decoration: const BoxDecoration(),
constraints: BoxConstraints( constraints: BoxConstraints(
...@@ -106,85 +109,92 @@ class _HomePageState extends State<HomePage> { ...@@ -106,85 +109,92 @@ class _HomePageState extends State<HomePage> {
future: _getApplications(context), future: _getApplications(context),
builder: (context, AsyncSnapshot<dynamic> snapshot) { builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData && snapshot.data != null) { if (snapshot.hasData && snapshot.data != null) {
return Column( return RefreshIndicator(
mainAxisAlignment: MainAxisAlignment.start, onRefresh: _pullRefresh,
crossAxisAlignment: CrossAxisAlignment.start, child: ListView(children: [
children: [ SingleChildScrollView(
Container( child: Column(
width: double.infinity, mainAxisAlignment: MainAxisAlignment.start,
margin: const EdgeInsets.only(top: 10, bottom: 20), crossAxisAlignment: CrossAxisAlignment.start,
child: Text('Today', children: [
style: GoogleFonts.lato( Container(
color: AppColors.black87, width: double.infinity,
fontSize: 16.0, margin: const EdgeInsets.only(top: 10, bottom: 20),
letterSpacing: 0.12, child: Text(AppLocalizations.of(context)!.today,
fontWeight: FontWeight.w600, style: GoogleFonts.lato(
)), color: AppColors.black87,
), fontSize: 16.0,
ListView.builder( letterSpacing: 0.12,
shrinkWrap: true, fontWeight: FontWeight.w600,
physics: const NeverScrollableScrollPhysics(), )),
itemCount: _pendingApplications.length,
itemBuilder: (context, i) {
return ApplicationCard(
application: _pendingApplications[i]);
},
),
Container(
width: double.infinity,
margin: const EdgeInsets.only(top: 20, bottom: 20),
child: Text('Upcoming',
style: GoogleFonts.lato(
color: AppColors.black87,
fontSize: 16.0,
letterSpacing: 0.12,
fontWeight: FontWeight.w600,
)),
),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _upcomingApplications.length,
itemBuilder: (context, i) {
return ApplicationCard(
application: _upcomingApplications[i]);
},
),
Container(
height: 50,
width: double.infinity,
margin: const EdgeInsets.only(top: 20),
child: ButtonTheme(
child: OutlinedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PastApplications(
pastApplications: _pastApplications)),
);
},
style: OutlinedButton.styleFrom(
// primary: Colors.white,
side: const BorderSide(
width: 1, color: AppColors.primaryBlue),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
// onSurface: Colors.grey,
), ),
child: Text( ListView.builder(
'View past applications', shrinkWrap: true,
style: GoogleFonts.lato( physics: const NeverScrollableScrollPhysics(),
color: AppColors.primaryBlue, itemCount: _pendingApplications.length,
fontSize: 14, itemBuilder: (context, i) {
fontWeight: FontWeight.w700), return ApplicationCard(
application: _pendingApplications[i]);
},
), ),
), Container(
), width: double.infinity,
) margin: const EdgeInsets.only(top: 20, bottom: 20),
], child: Text(AppLocalizations.of(context)!.upcoming,
); style: GoogleFonts.lato(
color: AppColors.black87,
fontSize: 16.0,
letterSpacing: 0.12,
fontWeight: FontWeight.w600,
)),
),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _upcomingApplications.length,
itemBuilder: (context, i) {
return ApplicationCard(
application: _upcomingApplications[i]);
},
),
Container(
height: 50,
width: double.infinity,
margin: const EdgeInsets.only(top: 20),
child: ButtonTheme(
child: OutlinedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PastApplications(
pastApplications:
_pastApplications)),
);
},
style: OutlinedButton.styleFrom(
// primary: Colors.white,
side: const BorderSide(
width: 1, color: AppColors.primaryBlue),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
// onSurface: Colors.grey,
),
child: Text(
AppLocalizations.of(context)!
.viewPastApplications,
style: GoogleFonts.lato(
color: AppColors.primaryBlue,
fontSize: 14,
fontWeight: FontWeight.w700),
),
),
),
)
],
))
]));
} else { } else {
return const Center( return const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
...@@ -192,6 +202,6 @@ class _HomePageState extends State<HomePage> { ...@@ -192,6 +202,6 @@ class _HomePageState extends State<HomePage> {
} }
}, },
), ),
))); ));
} }
} }
This diff is collapsed.
...@@ -6,8 +6,8 @@ import 'package:smf_mobile/constants/color_constants.dart'; ...@@ -6,8 +6,8 @@ import 'package:smf_mobile/constants/color_constants.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:smf_mobile/pages/login_otp_page.dart'; import 'package:smf_mobile/pages/login_otp_page.dart';
import 'package:smf_mobile/repositories/login_repository.dart'; import 'package:smf_mobile/repositories/login_repository.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/util/helper.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LoginEmailPage extends StatefulWidget { class LoginEmailPage extends StatefulWidget {
static const route = AppUrl.loginEmailPage; static const route = AppUrl.loginEmailPage;
...@@ -22,11 +22,19 @@ class _LoginEmailPageState extends State<LoginEmailPage> { ...@@ -22,11 +22,19 @@ class _LoginEmailPageState extends State<LoginEmailPage> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
String _errorMessage = ''; String _errorMessage = '';
late Locale locale;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
} }
// This method should be triggered on some event
// _setLang() async {
// locale = const Locale('es', '');
// LandingPage.of(context)?.setLocale(locale);
// }
Future<void> _generateOtp() async { Future<void> _generateOtp() async {
final email = _emailController.text; final email = _emailController.text;
if (email == '') { if (email == '') {
...@@ -100,7 +108,7 @@ class _LoginEmailPageState extends State<LoginEmailPage> { ...@@ -100,7 +108,7 @@ class _LoginEmailPageState extends State<LoginEmailPage> {
child: Align( child: Align(
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
'Login', AppLocalizations.of(context)!.login,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
...@@ -115,7 +123,7 @@ class _LoginEmailPageState extends State<LoginEmailPage> { ...@@ -115,7 +123,7 @@ class _LoginEmailPageState extends State<LoginEmailPage> {
top: 50, top: 50,
), ),
child: Text( child: Text(
'Email Id', AppLocalizations.of(context)!.emailId,
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
...@@ -215,7 +223,8 @@ class _LoginEmailPageState extends State<LoginEmailPage> { ...@@ -215,7 +223,8 @@ class _LoginEmailPageState extends State<LoginEmailPage> {
Align( Align(
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
'GET OTP', AppLocalizations.of(context)!
.getOtp,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: Colors.white, color: Colors.white,
......
...@@ -8,8 +8,8 @@ import 'package:smf_mobile/pages/login_email_page.dart'; ...@@ -8,8 +8,8 @@ import 'package:smf_mobile/pages/login_email_page.dart';
import 'package:otp_text_field/otp_field.dart'; import 'package:otp_text_field/otp_field.dart';
import 'package:otp_text_field/style.dart'; import 'package:otp_text_field/style.dart';
import 'package:smf_mobile/repositories/login_repository.dart'; import 'package:smf_mobile/repositories/login_repository.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/util/helper.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LoginOtpPage extends StatefulWidget { class LoginOtpPage extends StatefulWidget {
static const route = AppUrl.loginOtpPage; static const route = AppUrl.loginOtpPage;
...@@ -97,7 +97,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> { ...@@ -97,7 +97,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> {
child: Align( child: Align(
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
'Login', AppLocalizations.of(context)!.login,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
...@@ -112,7 +112,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> { ...@@ -112,7 +112,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> {
top: 50, top: 50,
), ),
child: Text( child: Text(
'Enter OTP', AppLocalizations.of(context)!.enterOtp,
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
...@@ -165,7 +165,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> { ...@@ -165,7 +165,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> {
Padding( Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 30), padding: const EdgeInsets.fromLTRB(0, 0, 0, 30),
child: Text( child: Text(
'Enter the 6 digit OTP sent to your email address.', AppLocalizations.of(context)!.otpFieldDescription,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black60, color: AppColors.black60,
fontSize: 12, fontSize: 12,
...@@ -201,7 +201,8 @@ class _LoginOtpPageState extends State<LoginOtpPage> { ...@@ -201,7 +201,8 @@ class _LoginOtpPageState extends State<LoginOtpPage> {
Align( Align(
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
'SIGN IN', AppLocalizations.of(context)!
.signIn,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: Colors.white, color: Colors.white,
...@@ -224,7 +225,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> { ...@@ -224,7 +225,7 @@ class _LoginOtpPageState extends State<LoginOtpPage> {
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10), padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
width: double.infinity, width: double.infinity,
child: Text( child: Text(
'Go back, re-enter the email', AppLocalizations.of(context)!.goBackText,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.primaryBlue, color: AppColors.primaryBlue,
......
...@@ -3,6 +3,7 @@ import 'package:google_fonts/google_fonts.dart'; ...@@ -3,6 +3,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:smf_mobile/constants/color_constants.dart'; import 'package:smf_mobile/constants/color_constants.dart';
import 'package:smf_mobile/models/application_model.dart'; import 'package:smf_mobile/models/application_model.dart';
import 'package:smf_mobile/widgets/application_card.dart'; import 'package:smf_mobile/widgets/application_card.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class PastApplications extends StatefulWidget { class PastApplications extends StatefulWidget {
final List<Application> pastApplications; final List<Application> pastApplications;
...@@ -27,7 +28,7 @@ class _PastApplicationsState extends State<PastApplications> { ...@@ -27,7 +28,7 @@ class _PastApplicationsState extends State<PastApplications> {
backgroundColor: Colors.white, backgroundColor: Colors.white,
leading: const BackButton(color: AppColors.black60), leading: const BackButton(color: AppColors.black60),
title: Text( title: Text(
'Past applications', AppLocalizations.of(context)!.pastApplications,
style: GoogleFonts.lato( style: GoogleFonts.lato(
color: AppColors.black87, color: AppColors.black87,
fontSize: 16.0, fontSize: 16.0,
......
...@@ -30,7 +30,6 @@ class ApplicationRespository with ChangeNotifier { ...@@ -30,7 +30,6 @@ class ApplicationRespository with ChangeNotifier {
try { try {
final request = await ApplicationService.submitInspection(data); final request = await ApplicationService.submitInspection(data);
_data = json.decode(request.body); _data = json.decode(request.body);
print(_data);
} catch (_) { } catch (_) {
return _; return _;
} }
......
import 'dart:convert';
import 'package:flutter/widgets.dart';
import 'package:smf_mobile/services/form_service.dart';
import 'package:smf_mobile/models/form_model.dart';
// import 'dart:developer' as developer;
class FormRespository with ChangeNotifier {
late Map _data;
late FormData _formData;
String _errorMessage = '';
Future<dynamic> getFormDetails(int formId) async {
try {
final request = await FormService.getFormDetails(formId);
_data = json.decode(request.body);
} catch (_) {
return _;
}
if (_data['statusInfo']['statusCode'] != 200) {
_errorMessage = _data['statusInfo']['errorMessage'];
} else {
_formData = FormData.fromJson(_data['responseData']);
}
return _formData;
}
String get errorMessage => _errorMessage;
}
import 'dart:convert';
import 'package:flutter/widgets.dart';
// import 'package:smf_mobile/models/application_model.dart';
import 'package:smf_mobile/services/user_service.dart';
class UserRespository with ChangeNotifier {
late Map _data;
// List<Application> _applications = [];
String _errorMessage = '';
Future<dynamic> getAllUsers() async {
try {
final request = await UserService.getAllUsers();
_data = json.decode(request.body);
} catch (_) {
return _;
}
if (_data['statusInfo']['statusCode'] != 200) {
_errorMessage = _data['statusInfo']['errorMessage'];
} else {
// _applications = [
// for (final item in _data['responseData']) Application.fromJson(item)
// ];
}
// return _applications;
return _data;
}
String get errorMessage => _errorMessage;
}
...@@ -2,17 +2,17 @@ import 'dart:convert'; ...@@ -2,17 +2,17 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:smf_mobile/constants/api_endpoints.dart'; import 'package:smf_mobile/constants/api_endpoints.dart';
import 'package:smf_mobile/constants/app_constants.dart';
import 'package:smf_mobile/services/base_service.dart'; import 'package:smf_mobile/services/base_service.dart';
import 'package:smf_mobile/util/helper.dart'; // import 'dart:developer' as developer;
import 'dart:developer' as developer;
class ApplicationService extends BaseService { class ApplicationService extends BaseService {
ApplicationService(HttpClient client) : super(client); ApplicationService(HttpClient client) : super(client);
static Future<dynamic> getApplications() async { static Future<dynamic> getApplications() async {
Map requestData = {'searchObjects': []}; Map requestData = {'status': InspectionStatus.sentForInspection};
var body = json.encode(requestData); var body = json.encode(requestData);
Map<String, String> headers = await Helper.getHeaders(); Map<String, String> headers = await BaseService.getHeaders();
final response = await http.post(Uri.parse(ApiUrl.getAllApplications), final response = await http.post(Uri.parse(ApiUrl.getAllApplications),
headers: headers, body: body); headers: headers, body: body);
...@@ -22,10 +22,13 @@ class ApplicationService extends BaseService { ...@@ -22,10 +22,13 @@ class ApplicationService extends BaseService {
static Future<dynamic> submitInspection(Map data) async { static Future<dynamic> submitInspection(Map data) async {
var body = json.encode(data); var body = json.encode(data);
Map<String, String> headers = await Helper.getHeaders(); Map<String, String> headers = await BaseService.getHeaders();
// developer.log(ApiUrl.submitInspection);
final response = await http.post(Uri.parse(ApiUrl.submitInspection), final response = await http.post(Uri.parse(ApiUrl.submitInspection),
headers: headers, body: body); headers: headers, body: body);
// developer.log(ApiUrl.submitInspection);
// developer.log(body);
// developer.log(response.body);
return response; return response;
} }
} }
import 'dart:io'; import 'dart:io';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
const _storage = FlutterSecureStorage();
abstract class BaseService { abstract class BaseService {
final HttpClient client; final HttpClient client;
const BaseService(this.client); const BaseService(this.client);
static Future<Map<String, String>> getHeaders() async {
Map<String, String> headers = {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
};
var authToken = await _storage.read(key: 'authToken');
if (authToken != '' && authToken != null) {
headers['Authorization'] = authToken;
}
return headers;
}
} }
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:smf_mobile/constants/api_endpoints.dart';
import 'package:smf_mobile/services/base_service.dart';
// import 'dart:developer' as developer;
class FormService extends BaseService {
FormService(HttpClient client) : super(client);
static Future<dynamic> getFormDetails(int formId) async {
Map<String, String> headers = await BaseService.getHeaders();
final response = await http.get(
Uri.parse(ApiUrl.getFormDetails + formId.toString()),
headers: headers);
// developer.log(ApiUrl.getAllUsers);
// developer.log(headers.toString());
// developer.log(response.body);
return response;
}
}
...@@ -3,7 +3,6 @@ import 'dart:io'; ...@@ -3,7 +3,6 @@ import 'dart:io';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:smf_mobile/constants/api_endpoints.dart'; import 'package:smf_mobile/constants/api_endpoints.dart';
import 'package:smf_mobile/services/base_service.dart'; import 'package:smf_mobile/services/base_service.dart';
import 'package:smf_mobile/util/helper.dart';
// import 'dart:developer' as developer; // import 'dart:developer' as developer;
class LoginService extends BaseService { class LoginService extends BaseService {
...@@ -14,7 +13,7 @@ class LoginService extends BaseService { ...@@ -14,7 +13,7 @@ class LoginService extends BaseService {
'username': username, 'username': username,
}; };
var body = json.encode(requestData); var body = json.encode(requestData);
Map<String, String> headers = await Helper.getHeaders(); Map<String, String> headers = await BaseService.getHeaders();
final response = final response =
await http.post(Uri.parse(ApiUrl.getOtp), headers: headers, body: body); await http.post(Uri.parse(ApiUrl.getOtp), headers: headers, body: body);
return response; return response;
...@@ -23,7 +22,7 @@ class LoginService extends BaseService { ...@@ -23,7 +22,7 @@ class LoginService extends BaseService {
static Future<dynamic> validateOtp(String username, String otp) async { static Future<dynamic> validateOtp(String username, String otp) async {
Map requestData = {'username': username, 'otp': otp}; Map requestData = {'username': username, 'otp': otp};
var body = json.encode(requestData); var body = json.encode(requestData);
Map<String, String> headers = await Helper.getHeaders(); Map<String, String> headers = await BaseService.getHeaders();
final response = await http.post(Uri.parse(ApiUrl.validateOtp), final response = await http.post(Uri.parse(ApiUrl.validateOtp),
headers: headers, body: body); headers: headers, body: body);
return response; return response;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment