Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.78 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
  3. import 'package:scoped_model/scoped_model.dart';
  4. import 'package:flutter_secure_storage/flutter_secure_storage.dart';
  5. import '../widget/drawer.dart';
  6. import '../widget/helpers/lower_case_string.dart';
  7. import '../logic/main_logic.dart';
  8.  
  9. class Profile extends StatefulWidget {
  10.   @override
  11.   State<StatefulWidget> createState() {
  12.     return _ProfileState();
  13.   }
  14. }
  15.  
  16. class _ProfileState extends State<Profile> {
  17.   final FlutterSecureStorage _storage = FlutterSecureStorage();
  18.   final String title = 'Profilo';
  19.   Color _color = Colors.blueAccent;
  20.  
  21.   @override
  22.   void initState() {
  23.     _readColor();
  24.     super.initState();
  25.   }
  26.  
  27.   Future<Null> _readColor() async {
  28.     final String _storedColor = await _storage.read(key: 'color');
  29.     if (_storedColor == null) {
  30.       setState(() {
  31.         _color = Colors.blueAccent;
  32.       });
  33.     } else {
  34.       final int color = int.parse(
  35.           _storedColor.replaceAll('Color(', '').replaceAll(')', '').trim());
  36.       setState(() {
  37.         _color = Color(color);
  38.       });
  39.     }
  40.   }
  41.  
  42.   @override
  43.   Widget build(BuildContext context) {
  44.     final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  45.     return Scaffold(
  46.       key: _scaffoldKey,
  47.       endDrawer: DrawerWidget(title),
  48.       appBar: AppBar(
  49.         actions: <Widget>[
  50.           IconButton(
  51.               onPressed: () => _changeColor(context), icon: Icon(Icons.edit)),
  52.           IconButton(
  53.             onPressed: () => _scaffoldKey.currentState.openEndDrawer(),
  54.             icon: Icon(Icons.menu),
  55.           )
  56.         ],
  57.         centerTitle: true,
  58.         title: Text(title),
  59.       ),
  60.       body: ScopedModelDescendant<MainModel>(
  61.         builder: (BuildContext context, Widget child, MainModel model) {
  62.           Widget content = Center(
  63.             child: Text('Caricamento'),
  64.           );
  65.           if (model.student.address != null && !model.isLoading) {
  66.             content = _body(model, context);
  67.           } else if (model.isLoading) {
  68.             content = Center(
  69.               child: CircularProgressIndicator(),
  70.             );
  71.           }
  72.           return RefreshIndicator(
  73.             onRefresh: model.loadData,
  74.             child: content,
  75.           );
  76.         },
  77.       ),
  78.     );
  79.   }
  80.  
  81.   void _changeColor(BuildContext context) {
  82.     showDialog(
  83.       context: context,
  84.       builder: (BuildContext context) {
  85.         return AlertDialog(
  86.           title: Text('Seleziona un colore'),
  87.           content: MaterialColorPicker(
  88.               circleSize: 50,
  89.               onColorChange: (Color color) {
  90.                 setState(() {
  91.                   _color = color;
  92.                 });
  93.               },
  94.               selectedColor: _color),
  95.           actions: <Widget>[
  96.             FlatButton(
  97.               child: Text('Fatto'),
  98.               onPressed: () async {
  99.                 await _storage.write(
  100.                     key: 'color', value: '${_color.toString()}');
  101.                 Navigator.of(context).pop();
  102.               },
  103.             )
  104.           ],
  105.         );
  106.       },
  107.     );
  108.   }
  109.  
  110.   Widget _body(MainModel model, BuildContext context) {
  111.     return Stack(
  112.       children: <Widget>[
  113.         ClipPath(
  114.           child: Container(
  115.             color: _color.withOpacity(0.8),
  116.           ),
  117.           clipper: GetClipper(),
  118.         ),
  119.         Positioned(
  120.           top: MediaQuery.of(context).size.height / 2,
  121.           left: MediaQuery.of(context).size.width / 2,
  122.           child: Column(
  123.             children: <Widget>[
  124.               _buildAvatar(model, _color),
  125.               SizedBox(height: 90.0),
  126.               Center(
  127.                 child: Row(
  128.                   mainAxisAlignment: MainAxisAlignment.center,
  129.                   children: <Widget>[
  130.                     BuildString(model.student.name, 20, FontStyle.normal,
  131.                         FontWeight.bold),
  132.                     SizedBox(width: 5),
  133.                     BuildString(model.student.surname, 20, FontStyle.normal,
  134.                         FontWeight.bold),
  135.                     SizedBox(width: 5),
  136.                     Text('${model.school.type + model.student.course}',
  137.                         style: TextStyle(
  138.                             fontSize: 20, fontWeight: FontWeight.bold)),
  139.                   ],
  140.                 ),
  141.               ),
  142.               SizedBox(height: 20.0),
  143.               Center(child: BuildString(model.school.instituteName))
  144.             ],
  145.           ),
  146.         ),
  147.       ],
  148.     );
  149.   }
  150. }
  151.  
  152. Widget _buildAvatar(MainModel model, Color color) {
  153.   return Container(
  154.     width: 160.0,
  155.     height: 160.0,
  156.     child: Center(
  157.       child: Stack(
  158.         alignment: AlignmentDirectional.center,
  159.         children: <Widget>[
  160.           Center(
  161.             child: Icon(
  162.               Icons.lens,
  163.               color: Colors.white,
  164.               size: 160,
  165.             ),
  166.           ),
  167.           Container(
  168.             child: Text(
  169.               '${model.student.name.substring(0, 1) + model.student.surname.substring(0, 1)}',
  170.               style: TextStyle(
  171.                   color: color, fontSize: 50, fontWeight: FontWeight.w500),
  172.             ),
  173.           )
  174.         ],
  175.       ),
  176.     ),
  177.     decoration: BoxDecoration(
  178.         borderRadius: BorderRadius.all(Radius.circular(75.0)),
  179.         boxShadow: [
  180.           BoxShadow(blurRadius: 40.0, color: color),
  181.         ]),
  182.   );
  183. }
  184.  
  185. class GetClipper extends CustomClipper<Path> {
  186.   @override
  187.   Path getClip(Size size) {
  188.     var path = Path();
  189.     path.lineTo(0.0, size.height / 1.9);
  190.     path.lineTo(size.width + 150, 0.0);
  191.     path.close();
  192.     return path;
  193.   }
  194.  
  195.   @override
  196.   bool shouldReclip(CustomClipper<Path> oldClipper) {
  197.     return true;
  198.   }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement