Untitled
unknown
dart
2 years ago
3.7 kB
4
Indexable
import 'dart:convert'; import 'package:elira_dev/Services/auth_service.dart'; import 'package:elira_dev/Services/globals.dart'; import 'package:flutter/cupertino.dart'; import 'package:elira_dev/rounded_button.dart'; import 'package:flutter/material.dart'; import 'home_screen.dart'; import 'login_screen.dart'; import 'package:http/http.dart' as http; class RegisterScreen extends StatefulWidget{ const RegisterScreen({Key? key}) : super(key: key); @override _RegisterScreenState createState() => _RegisterScreenState(); } class _RegisterScreenState extends State<RegisterScreen>{ String _email = ''; String _password = ''; String _name = ''; createAccountPressed() async{ bool emailValid = RegExp( r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+") .hasMatch(_email); if(emailValid){ http.Response response = await AuthServices.register(_name, _email, _password); Map responseMap = jsonDecode(response.body); if(response.statusCode==200){ Navigator.push( context, MaterialPageRoute( builder: (BuildContext context)=> const HomeScreen(), )); } else{ errorSnackBar(context, responseMap.values.first[0]); } } else{ errorSnackBar(context, 'Geçersiz mail adresi'); } } @override Widget build(BuildContext context){ return Scaffold( appBar: AppBar( backgroundColor: Colors.black, centerTitle: true, elevation: 0, title: Text( 'Kayıt Ol', style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, ) ) ), body: Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: Column( children: [ const SizedBox( height: 20, ), TextField( decoration: const InputDecoration( hintText: 'İsim', ), onChanged: (value){ _name = value; }, ), const SizedBox( height: 30, ), TextField( decoration: const InputDecoration( hintText: 'Mail', ), onChanged: (value){ _email = value; }, ), const SizedBox( height: 30, ), TextField( obscureText: true, decoration: const InputDecoration( hintText: 'Şifre', ), onChanged: (value){ _password = value; }, ), const SizedBox( height: 40, ), RoundedButton( btnText: 'Hesap Oluştur', onBtnPressed: ()=> createAccountPressed(), ), const SizedBox( height: 40, ), GestureDetector( onTap: (){ Navigator.push( context, MaterialPageRoute( builder: (BuildContext context)=> const LoginScreen(), )); }, child: Text( 'Zaten Hesabım Var', style: TextStyle( decoration: TextDecoration.underline, ), ), ) ], ) ) ); } }
Editor is loading...