Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
- import 'package:scoped_model/scoped_model.dart';
- import 'package:flutter_secure_storage/flutter_secure_storage.dart';
- import '../widget/drawer.dart';
- import '../widget/helpers/lower_case_string.dart';
- import '../logic/main_logic.dart';
- class Profile extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- return _ProfileState();
- }
- }
- class _ProfileState extends State<Profile> {
- final FlutterSecureStorage _storage = FlutterSecureStorage();
- final String title = 'Profilo';
- Color _color = Colors.blueAccent;
- @override
- void initState() {
- _readColor();
- super.initState();
- }
- Future<Null> _readColor() async {
- final String _storedColor = await _storage.read(key: 'color');
- if (_storedColor == null) {
- setState(() {
- _color = Colors.blueAccent;
- });
- } else {
- final int color = int.parse(
- _storedColor.replaceAll('Color(', '').replaceAll(')', '').trim());
- setState(() {
- _color = Color(color);
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
- return Scaffold(
- key: _scaffoldKey,
- endDrawer: DrawerWidget(title),
- appBar: AppBar(
- actions: <Widget>[
- IconButton(
- onPressed: () => _changeColor(context), icon: Icon(Icons.edit)),
- IconButton(
- onPressed: () => _scaffoldKey.currentState.openEndDrawer(),
- icon: Icon(Icons.menu),
- )
- ],
- centerTitle: true,
- title: Text(title),
- ),
- body: ScopedModelDescendant<MainModel>(
- builder: (BuildContext context, Widget child, MainModel model) {
- Widget content = Center(
- child: Text('Caricamento'),
- );
- if (model.student.address != null && !model.isLoading) {
- content = _body(model, context);
- } else if (model.isLoading) {
- content = Center(
- child: CircularProgressIndicator(),
- );
- }
- return RefreshIndicator(
- onRefresh: model.loadData,
- child: content,
- );
- },
- ),
- );
- }
- void _changeColor(BuildContext context) {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return AlertDialog(
- title: Text('Seleziona un colore'),
- content: MaterialColorPicker(
- circleSize: 50,
- onColorChange: (Color color) {
- setState(() {
- _color = color;
- });
- },
- selectedColor: _color),
- actions: <Widget>[
- FlatButton(
- child: Text('Fatto'),
- onPressed: () async {
- await _storage.write(
- key: 'color', value: '${_color.toString()}');
- Navigator.of(context).pop();
- },
- )
- ],
- );
- },
- );
- }
- Widget _body(MainModel model, BuildContext context) {
- return Stack(
- children: <Widget>[
- ClipPath(
- child: Container(
- color: _color.withOpacity(0.8),
- ),
- clipper: GetClipper(),
- ),
- Positioned(
- top: MediaQuery.of(context).size.height / 2,
- left: MediaQuery.of(context).size.width / 2,
- child: Column(
- children: <Widget>[
- _buildAvatar(model, _color),
- SizedBox(height: 90.0),
- Center(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- BuildString(model.student.name, 20, FontStyle.normal,
- FontWeight.bold),
- SizedBox(width: 5),
- BuildString(model.student.surname, 20, FontStyle.normal,
- FontWeight.bold),
- SizedBox(width: 5),
- Text('${model.school.type + model.student.course}',
- style: TextStyle(
- fontSize: 20, fontWeight: FontWeight.bold)),
- ],
- ),
- ),
- SizedBox(height: 20.0),
- Center(child: BuildString(model.school.instituteName))
- ],
- ),
- ),
- ],
- );
- }
- }
- Widget _buildAvatar(MainModel model, Color color) {
- return Container(
- width: 160.0,
- height: 160.0,
- child: Center(
- child: Stack(
- alignment: AlignmentDirectional.center,
- children: <Widget>[
- Center(
- child: Icon(
- Icons.lens,
- color: Colors.white,
- size: 160,
- ),
- ),
- Container(
- child: Text(
- '${model.student.name.substring(0, 1) + model.student.surname.substring(0, 1)}',
- style: TextStyle(
- color: color, fontSize: 50, fontWeight: FontWeight.w500),
- ),
- )
- ],
- ),
- ),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(75.0)),
- boxShadow: [
- BoxShadow(blurRadius: 40.0, color: color),
- ]),
- );
- }
- class GetClipper extends CustomClipper<Path> {
- @override
- Path getClip(Size size) {
- var path = Path();
- path.lineTo(0.0, size.height / 1.9);
- path.lineTo(size.width + 150, 0.0);
- path.close();
- return path;
- }
- @override
- bool shouldReclip(CustomClipper<Path> oldClipper) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement