Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
import 'package:flutter/material.dart'; import 'package:umessage/contstrains/app_colors.dart'; import 'package:umessage/http_api_client.dart'; import 'package:umessage/locator.dart'; import 'package:umessage/widgets/navbar/navbar_tablet_desktop.dart'; class AuthView extends StatefulWidget { AuthView({Key key}) : super(key: key); @override _AuthViewState createState() => _AuthViewState(); } class _AuthViewState extends State<AuthView> { TextEditingController _emailController = TextEditingController(); TextEditingController _passwordController = TextEditingController(); bool rememberMe = false; ApiClient apiClient = ApiClient.getInstance(); @override Widget build(BuildContext context) { return Center( child: Padding( padding: EdgeInsets.only(top: 150, left: 60, right: 60), child: Column( children: <Widget>[ Text( 'Авторизация', style: TextStyle( fontWeight: FontWeight.w600, fontSize: 28, color: textColor), ), SizedBox( height: 40, ), _input(Icon(Icons.mail), 'Email', _emailController, false, 15), SizedBox( height: 15, ), _input(Icon(Icons.lock), 'Password', _passwordController, true, 15), SizedBox( height: 5, ), Container( padding: EdgeInsets.only(left: 20, right: 20), width: 460, child: Theme( data: ThemeData( splashColor: Colors.transparent, highlightColor: Colors.transparent, hoverColor: Colors.transparent), child: CheckboxListTile( title: Text( 'Запомнить меня', style: TextStyle(color: textColor), ), value: rememberMe, onChanged: (bool value) { setState(() { rememberMe = value; }); }, ))), SizedBox( height: 5, ), _button('Войти', auth, 15), SizedBox( height: 15, ), Container( width: 460, child: Align( alignment: Alignment.bottomCenter, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Пройдите ', style: TextStyle(color: Colors.white, fontSize: 12), ), Text( 'регистрацию, ', style: TextStyle(color: linkColor, fontSize: 12), ), Text( 'если вы этого еще не сделали', style: TextStyle(color: Colors.white, fontSize: 12), ), ], )), ), ], ), )); } Widget _input(Icon icon, String hint, TextEditingController controller, bool obscure, double borderRadius) { return Container( width: 460, height: 50, padding: EdgeInsets.only(left: 20, right: 20), child: TextField( controller: controller, obscureText: obscure, style: TextStyle(fontSize: 16, color: Colors.white), decoration: InputDecoration( border: OutlineInputBorder(), isDense: true, // Added this contentPadding: EdgeInsets.all(8), // hintStyle: TextStyle( fontWeight: FontWeight.bold, fontSize: 16, color: Colors.white), hintText: hint, focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(borderRadius), borderSide: BorderSide(color: Colors.white, width: 2)), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(borderRadius), borderSide: BorderSide(color: Colors.white54, width: 1)), prefixIcon: Padding( padding: EdgeInsets.only(left: 10, right: 10), child: IconTheme( data: IconThemeData(color: Colors.white), child: icon, ), )), ), ); } Widget _button(String label, void func(), double borderRadius) { return Container( width: 460, padding: EdgeInsets.only(left: 20, right: 20), child: RaisedButton( onPressed: () { apiClient .authorization(_emailController.text, _passwordController.text) .then((value) { func(); }); }, highlightColor: Theme.of(context).primaryColor, color: buttonPrimaryColor, child: Text('Войти', style: TextStyle( fontWeight: FontWeight.bold, color: textButtonColor, fontSize: 16)), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(borderRadius)), )); } void auth() { var state = navBar<NavBarDesktop>().navBarSate; setState(() { state.update(); }); } } class AuthorizationView extends StatelessWidget { const AuthorizationView({Key key}) : super(key: key); @override Widget build(BuildContext context) {} }
import 'package:flutter/material.dart'; import 'package:umessage/http_api_client.dart'; import 'package:umessage/routing/route_names.dart'; import 'navbar_item.dart'; import 'navbar_logo.dart'; class NavBarDesktop extends StatefulWidget { GlobalKey<_NavBarDesktopState> navBarDesktop = GlobalKey<_NavBarDesktopState>(); String login = 'None'; _NavBarDesktopState navBarSate = new _NavBarDesktopState(); NavBarDesktop({Key key}) : super(key: key); @override _NavBarDesktopState createState() => navBarSate; } class _NavBarDesktopState extends State<NavBarDesktop> { String username = ''; String loginButtonTitle = 'Войти'; @override void initState() { super.initState(); } void update() { setState(() { if (ApiClient.username.length > 0) loginButtonTitle = ApiClient.username; }); } @override Widget build(BuildContext context) { return Container( height: 60, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ NavBarIcon(), SizedBox(width: 30), Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ NavBarItem('Главная', HomeRoute), SizedBox(width: 30), NavBarItem('О нас', AboutRoute), SizedBox(width: 30), NavBarItem(loginButtonTitle, AuthRoute), SizedBox(width: 30), Text(widget.login), ], ) ], ), ); } }
GetIt navBar = GetIt.instance; navBar.registerLazySingleton(() => NavBarDesktop());