mirror of
https://github.com/hmalik144/days_left_flutter.git
synced 2026-03-17 23:16:12 +00:00
- 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:
23
lib/widgets/ButtonWidget.dart
Normal file
23
lib/widgets/ButtonWidget.dart
Normal 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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
74
lib/widgets/CodeEnterWidget.dart
Normal file
74
lib/widgets/CodeEnterWidget.dart
Normal 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'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
))),
|
||||
);
|
||||
}
|
||||
}
|
||||
85
lib/widgets/DisplayUserDetails.dart
Normal file
85
lib/widgets/DisplayUserDetails.dart
Normal 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"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
61
lib/widgets/LoaderWidget.dart
Normal file
61
lib/widgets/LoaderWidget.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
26
lib/widgets/TextDetailWidget.dart
Normal file
26
lib/widgets/TextDetailWidget.dart
Normal 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
28
lib/widgets/router.dart
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user