- Introduction on base view model and stateless widget classes

- Implementation of firebase
- Implementation of dependency injection

Took 11 hours 26 minutes
This commit is contained in:
2021-07-24 20:54:18 +01:00
parent 3d438ffc5b
commit f83071fa78
27 changed files with 1438 additions and 150 deletions

View File

@@ -0,0 +1,23 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ButtonWidget extends StatelessWidget{
final String label;
final Function onPressed;
ButtonWidget(this.label, {this.onPressed});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 20, bottom: 12),
child: ElevatedButton(
onPressed: onPressed,
child: Text(label),
),
);
}
}

View File

@@ -0,0 +1,74 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class CodeEnterWidget extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
final GlobalKey<ScaffoldState> scaffoldPageOne;
CodeEnterWidget({this.scaffoldPageOne});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Form(
key: _formKey,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text(
"Sign in with your phone number below.",
style: TextStyle(color: Colors.white),
),
color: Colors.blue,
alignment: Alignment.center,
padding: EdgeInsets.all(20.0),
),
TextFormField(
keyboardType: TextInputType.phone,
validator: (value) {
if (value.isEmpty) {
return 'Enter the code sent to you';
}
return null;
},
),
Container(
margin: EdgeInsets.only(top: 20, bottom: 12),
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
scaffoldPageOne.currentState.showSnackBar(
SnackBar(content: Text('Processing Data')));
}
Timer(Duration(seconds: 2), () {
// Todo: change body
});
},
child: Text('Submit'),
),
),
],
),
))),
);
}
}

View File

@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:days_left/constants/constants.dart';
import 'package:days_left/model/UserProfileDetails.dart';
import 'package:days_left/services/NavigationService.dart';
import '../locator.dart';
import 'TextDetailWidget.dart';
class DisplayUserDetails extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
final NavigationService _navigationService = locator<NavigationService>();
final UserProfileDetails userDetails;
final Function callback;
DisplayUserDetails(this.userDetails, this.callback);
@override
Widget build(BuildContext context) {
return Center(
child: Form(
key: _formKey,
child: Container(
width: 400,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
),
margin: EdgeInsets.all(20.0),
padding: EdgeInsets.all(12.0),
child: getInnerWidget(context),
)),
);
}
Widget getInnerWidget(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text(
"User Profile",
style: TextStyle(color: Colors.white),
),
color: Colors.blue,
alignment: Alignment.center,
padding: EdgeInsets.all(20.0),
),
_getInnerWidgetList(),
Container(
margin: EdgeInsets.only(top: 20, bottom: 12),
child: ElevatedButton(
onPressed: () {
_navigationService.navigateTo(UpdateDetailsViewRoute,
arguments: userDetails);
},
child: Text('Update'),
),
)
],
);
}
Widget _getInnerWidgetList() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextDetailWidget("Name", userDetails?.name ?? "n/a"),
TextDetailWidget("D.O.B", userDetails?.dob ?? "n/a"),
TextDetailWidget("Email", userDetails?.email ?? "n/a"),
TextDetailWidget("Phone no.", userDetails?.phone ?? "n/a"),
TextDetailWidget("Sex", userDetails?.sex ?? "n/a"),
]);
}
}

View File

@@ -0,0 +1,61 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class LoaderWidget extends StatefulWidget {
final Widget body;
LoaderWidget({this.body, Key key}): super(key: key);
@override
LoaderWidgetState createState() => LoaderWidgetState();
}
class LoaderWidgetState extends State<LoaderWidget> {
bool _status = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: _status ? Center(child: CircularProgressIndicator())
: Center(
child: widget.body,
),
);
}
void changeState(){
setState(() {
_status = !_status;
});
}
}
abstract class LoaderStatelessWidget extends StatelessWidget{
final loaderKey = GlobalKey<LoaderWidgetState>();
void changeState(){
loaderKey.currentState.changeState();
}
Widget LoaderWidgeted({Widget body}){
return LoaderWidget(body: body, key: loaderKey);
}
}
abstract class LoaderStatefulWidget<T extends StatefulWidget> extends State<T>{
final loaderKey = GlobalKey<LoaderWidgetState>();
void changeState(){
loaderKey.currentState.changeState();
}
Widget LoaderWidgeted(Widget body, Key key){
return LoaderWidget(body: body, key: key);
}
}

View File

@@ -0,0 +1,26 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class TextDetailWidget extends StatelessWidget {
final String labelText;
final String bodyText;
TextDetailWidget(this.labelText, this.bodyText);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
labelText,
style: TextStyle(color: Colors.blue),
),
Text(
bodyText,
style: TextStyle(color: Colors.black),
)
]);
}
}

28
lib/widgets/router.dart Normal file
View File

@@ -0,0 +1,28 @@
import 'package:days_left/login/login_screen_6.dart';
import 'package:flutter/material.dart';
import '../constants/constants.dart';
Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case LoginViewRoute:
return _getPageRoute(
routeName: settings.name,
viewToShow: LoginScreen6(),
);
default:
return MaterialPageRoute(
builder: (_) => Scaffold(
body: Center(
child: Text('No route defined for ${settings.name}')),
));
}
}
PageRoute _getPageRoute({String routeName, Widget viewToShow}) {
return MaterialPageRoute(
settings: RouteSettings(
name: routeName,
),
builder: (_) => viewToShow);
}