add structure
This commit is contained in:
392
lib/pages/profile_page.dart
Normal file
392
lib/pages/profile_page.dart
Normal file
@@ -0,0 +1,392 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/model/user_model.dart';
|
||||
import 'package:fcs/pages/profile_edit.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/vo/role.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/localization/transalation.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
import 'profile_setting.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class Profile extends StatefulWidget {
|
||||
@override
|
||||
_ProfileState createState() => _ProfileState();
|
||||
}
|
||||
|
||||
class _ProfileState extends State<Profile> {
|
||||
bool _isLoading = false;
|
||||
String selectedLanguage;
|
||||
TextEditingController bizNameController = new TextEditingController();
|
||||
|
||||
static final List<String> languagesList = Translation().supportedLanguages;
|
||||
static final List<String> languageCodesList =
|
||||
Translation().supportedLanguagesCodes;
|
||||
|
||||
final Map<dynamic, dynamic> languagesMap = {
|
||||
languagesList[0]: languageCodesList[0],
|
||||
languagesList[1]: languageCodesList[1],
|
||||
};
|
||||
|
||||
buildLanguage(LanguageModel languageModel) async {
|
||||
var lan = await languageModel.load();
|
||||
if (this.selectedLanguage != lan) {
|
||||
setState(() {
|
||||
this.selectedLanguage = lan;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
|
||||
buildLanguage(languageModel);
|
||||
_selectedDropdown(String selected) {
|
||||
setState(() {
|
||||
selectedLanguage = selected;
|
||||
languageModel.saveLanguage(selectedLanguage);
|
||||
});
|
||||
}
|
||||
|
||||
final namebox = Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: Container(
|
||||
height: 45.0,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 0.0),
|
||||
child: Text(
|
||||
AppTranslations.of(context).text("profile.name"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal)
|
||||
: TextStyle(
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 30,
|
||||
),
|
||||
Container(
|
||||
child: Center(
|
||||
child: Text(
|
||||
mainModel.user == null ? "" : mainModel.user.name,
|
||||
style:
|
||||
TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
final phonenumberbox = Container(
|
||||
height: 45.0,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 0.0),
|
||||
child: Text(
|
||||
AppTranslations.of(context).text("profile.phone"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal)
|
||||
: TextStyle(
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 27,
|
||||
),
|
||||
Container(
|
||||
child: Center(
|
||||
child: Text(
|
||||
mainModel.user == null
|
||||
? ""
|
||||
: mainModel.user.phone == null ? '' : mainModel.user.phone,
|
||||
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
final emailBox = Container(
|
||||
padding: EdgeInsets.only(top: 10, left: 0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
AppTranslations.of(context).text("profile.email"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal)
|
||||
: TextStyle(
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
SizedBox(
|
||||
width: 35,
|
||||
),
|
||||
Text(
|
||||
mainModel.user == null
|
||||
? ""
|
||||
: mainModel.user.email == null || mainModel.user.email == ''
|
||||
? ''
|
||||
: mainModel.user.email,
|
||||
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final languageBox = Container(
|
||||
padding: EdgeInsets.only(bottom: 15, top: 7),
|
||||
child: Container(
|
||||
height: 45.0,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
AppTranslations.of(context).text("profile.language"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal)
|
||||
: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
Container(
|
||||
width: 140,
|
||||
padding: EdgeInsets.only(left: 30),
|
||||
child: Theme(
|
||||
data: new ThemeData(
|
||||
canvasColor: Colors.white,
|
||||
),
|
||||
child: DropdownButton(
|
||||
hint: Text("English"),
|
||||
value: selectedLanguage,
|
||||
isExpanded: true,
|
||||
iconSize: 40,
|
||||
items: languagesList
|
||||
.map<DropdownMenuItem<String>>((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: _selectedDropdown),
|
||||
)),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
final logoutbutton = Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: Card(
|
||||
elevation: 23,
|
||||
child: Container(
|
||||
height: 45.0,
|
||||
child: ButtonTheme(
|
||||
minWidth: 900.0,
|
||||
height: 100.0,
|
||||
child: FlatButton.icon(
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "profile.logout.confirm",
|
||||
() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
await mainModel.logout();
|
||||
// Navigator.of(context)
|
||||
// .pushNamedAndRemoveUntil("/", ModalRoute.withName('/'));
|
||||
Future.delayed(Duration(seconds: 1), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
label: Text(AppTranslations.of(context).text("profile.logout"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal)
|
||||
: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode")),
|
||||
icon: Icon(
|
||||
Icons.exit_to_app,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
Future<String> getVersionNumber() async {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
String version = packageInfo.version + "+" + packageInfo.buildNumber;
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
final versionbox = Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: Container(
|
||||
child: Center(
|
||||
child: FutureBuilder(
|
||||
future: getVersionNumber(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) =>
|
||||
Text(
|
||||
snapshot.hasData ? "v${snapshot.data}" : "Loading ...",
|
||||
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
|
||||
),
|
||||
)),
|
||||
));
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
AppTranslations.of(context).text("profile.title"),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ProfileEdit()),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.settings),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ProfileSetting()),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.only(
|
||||
left: 25.0,
|
||||
right: 25.0,
|
||||
),
|
||||
shrinkWrap: true,
|
||||
children: <Widget>[
|
||||
namebox,
|
||||
mainModel.isBuyer() ? Container() : getPrivilegeBox(context),
|
||||
phonenumberbox,
|
||||
mainModel.user == null
|
||||
? Container()
|
||||
: mainModel.user.email == null || mainModel.user.email == ''
|
||||
? Container()
|
||||
: emailBox,
|
||||
languageBox,
|
||||
logoutbutton,
|
||||
Divider(color: secondaryColor),
|
||||
versionbox,
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getPrivilegeBox(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
var userModel = Provider.of<UserModel>(context);
|
||||
|
||||
return ListTileTheme(
|
||||
contentPadding: EdgeInsets.all(0),
|
||||
child: ExpansionTile(
|
||||
title: Text(
|
||||
AppTranslations.of(context).text("profile.privilege"),
|
||||
style: languageModel.isEng
|
||||
? TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
)
|
||||
: TextStyle(
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontStyle: FontStyle.normal,
|
||||
fontFamily: "MyanmarUnicode"),
|
||||
),
|
||||
children: <Widget>[
|
||||
Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children:
|
||||
getRowPrivilegeWidget(userModel.getUserPrivileges())),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getRowPrivilegeWidget(List<Privilege> privileges) {
|
||||
return privileges.map((p) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(p.name,
|
||||
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal)),
|
||||
SizedBox(
|
||||
width: 30,
|
||||
),
|
||||
Container(
|
||||
child: Text(
|
||||
"- ${p.desc}",
|
||||
style: TextStyle(fontSize: 16.0, fontStyle: FontStyle.normal),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user