Files
cssd/lib/pages/my_info_screen.dart
T
2023-12-07 13:45:51 +03:30

191 lines
8.7 KiB
Dart
Executable File

// import 'package:cssd/widgets/LabelScreens/LabelDetails/header.dart';
import 'package:cssd/providers/connectivity.dart';
import 'package:cssd/widgets/Global/internet_error.dart';
import 'package:cssd/widgets/LabelScreens/Detail/header.dart';
import 'package:cssd/widgets/MyInfo/input_box.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import '../providers/auth.dart';
class MyInfoScreen extends StatefulWidget {
// static const route = '/MyInfoScreenRoute';
@override
State<StatefulWidget> createState() {
return _MyInfoScreenState();
}
}
class _MyInfoScreenState extends State<MyInfoScreen> {
Map<String, dynamic>? user;
TextEditingController usernameCTRL = new TextEditingController();
TextEditingController emailCTRL = new TextEditingController();
bool isInit = true;
@override
void didChangeDependencies() async {
if (isInit) {
var authObj = Provider.of<Auth>(context, listen: false);
user = await authObj.getUserData();
usernameCTRL.text = user!['name'] != null ? user!['name'] : '';
emailCTRL.text = user!['email'] != null ? user!['email'] : '';
isInit = false;
}
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
final _media = MediaQuery.of(context);
final double _devicewidth = _media.size.width;
final double _deviceBlockSize = _devicewidth / 100;
return SafeArea(
child: GestureDetector(
onTap: () {
FocusManager.instance.primaryFocus?.unfocus();
},
child: Scaffold(
appBar: AppBar(
titleSpacing: -10,
title: Text('Dashboard', style: TextStyle(color: Colors.white,),),
backgroundColor: Colors.black,
leading: IconButton(
icon: Icon(
Icons.keyboard_arrow_left,
color: Colors.white,
size: 35,
),
onPressed: () => Navigator.of(context).pop(),
),
),
body: Consumer<ConnectivityProvider>(
builder: (ct, connection, _) {
return connection.conStatus != 'offline'
? isInit
? Center(
child: CircularProgressIndicator(
color: Colors.black,
),
)
: ListView(
children: <Widget>[
InfoHeader(
deviceBlockSize: _deviceBlockSize,
label: 'My Info',
),
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: <Widget>[
InfoInputBox(
controller: usernameCTRL,
deviceBlockSize: _deviceBlockSize,
label: 'Full Name',
icon: FontAwesomeIcons.alignLeft,
inputType: TextInputType.text,
),
SizedBox(
height: 20,
),
TextFormField(
readOnly: true,
initialValue: user!['cell_number'],
decoration: InputDecoration(
icon: Icon(
Icons.call,
size: 6 * _deviceBlockSize,
),
labelStyle: TextStyle(
fontWeight: FontWeight.w100,
fontSize: 4 * _deviceBlockSize,
),
labelText: 'Cell Number',
isDense: true,
contentPadding: EdgeInsets.symmetric(
vertical: 2, horizontal: 3),
),
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.grey,
fontSize: 5 * _deviceBlockSize,
),
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
),
SizedBox(
height: 20,
),
InfoInputBox(
controller: emailCTRL,
deviceBlockSize: _deviceBlockSize,
label: 'Email Address',
icon: FontAwesomeIcons.envelope,
inputType: TextInputType.emailAddress,
),
SizedBox(
height: 40,
),
InkWell(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 60, vertical: 10),
margin:
EdgeInsets.only(top: 50, bottom: 20),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(5),
),
child: Text(
'Save',
style: TextStyle(
color: Colors.white,
fontSize: 5 * _deviceBlockSize,
),
textAlign: TextAlign.center,
),
),
onTap: () async {
await Provider.of<Auth>(context,
listen: false)
.setUserData(
user!['id'],
usernameCTRL.text,
emailCTRL.text,
)
.then(
(value) async => await showDialog(
context: context,
builder: (ctx) => AlertDialog(
content: Text(
'Info changed successfully.',
),
actions: <Widget>[
TextButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(ctx).pop();
},
),
],
),
),
);
Navigator.of(context).pop();
},
),
],
),
),
],
)
: ConnectionErrorBox();
},
),
),
),
);
}
}