I am building a code on flutter, this is a login form and bellow this there is a text called Sign Up, I want to put external website url. Can anyone help me on this?
This is the code
import 'dart:io';
import 'package:academy_app/constants.dart';
import 'package:academy_app/models/common_functions.dart';
import 'package:academy_app/providers/auth.dart';
import 'package:academy_app/screens/forgot_password_screen.dart';
import 'package:academy_app/screens/signup_screen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class AuthScreen extends StatefulWidget {
static const routeName = '/auth';
const AuthScreen({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_AuthScreenState createState() => _AuthScreenState();
}
class _AuthScreenState extends State<AuthScreen> {
GlobalKey<FormState> globalFormKey = GlobalKey<FormState>();
final scaffoldKey = GlobalKey<ScaffoldState>();
final Map<String, String> _authData = {
'email': '',
'password': '',
};
bool hidePassword = true;
bool _isLoading = false;
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
Color getColor(Set<MaterialState> states) {
const Set<MaterialState> interactiveStates = <MaterialState>{
MaterialState.pressed,
MaterialState.hovered,
MaterialState.focused,
};
if (states.any(interactiveStates.contains)) {
return Colors.blue;
}
return Colors.red;
}
InputDecoration getInputDecoration(String hintext, IconData iconData) {
return InputDecoration(
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.white, width: 2),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Colors.white, width: 2),
),
border: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
focusedErrorBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Color(0xFFF65054)),
),
errorBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
borderSide: BorderSide(color: Color(0xFFF65054)),
),
filled: true,
prefixIcon: Icon(
iconData,
color: kTextLowBlackColor,
),
hintStyle: const TextStyle(color: Colors.black54, fontSize: 14),
hintText: hintext,
fillColor: kBackgroundColor,
contentPadding: const EdgeInsets.symmetric(vertical: 18, horizontal: 15),
);
}
Future<void> _submit() async {
if (!globalFormKey.currentState!.validate()) {
// Invalid!
return;
}
globalFormKey.currentState!.save();
setState(() {
_isLoading = true;
});
try {
// Log user in
await Provider.of<Auth>(context, listen: false).login(
_authData['email'].toString(),
_authData['password'].toString(),
);
// ignore: use_build_context_synchronously
Navigator.pushNamedAndRemoveUntil(context, '/home', (r) => false);
CommonFunctions.showSuccessToast('Login Successful');
} on HttpException {
var errorMsg = 'Auth failed';
CommonFunctions.showErrorDialog(errorMsg, context);
} catch (error) {
// print(error);
const errorMsg = 'Could not authenticate!';
CommonFunctions.showErrorDialog(errorMsg, context);
}
setState(() {
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kBackgroundColor,
appBar: AppBar(
key: scaffoldKey,
elevation: 0,
iconTheme: const IconThemeData(color: kSelectItemColor),
backgroundColor: kBackgroundColor,
),
body: SingleChildScrollView(
child: Column(
children: [
Center(
child: Form(
key: globalFormKey,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 25,
),
CircleAvatar(
radius: 50,
backgroundColor: kBackgroundColor,
child: Image.asset(
'assets/images/do_login.png',
height: 70,
),
),
const SizedBox(
height: 10,
),
const Text(
'Log in',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 20),
const Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.only(left: 17.0, bottom: 5.0),
child: Text(
'Email',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 15.0, top: 0.0, right: 15.0, bottom: 8.0),
child: TextFormField(
style: const TextStyle(fontSize: 14),
decoration: getInputDecoration(
'Email',
Icons.email_outlined,
),
controller: _emailController,
keyboardType: TextInputType.emailAddress,
validator: (input) =>
!RegExp(r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
.hasMatch(input!)
? "Email Id should be valid"
: null,
onSaved: (value) {
_authData['email'] = value.toString();
_emailController.text = value as String;
},
),
),
const SizedBox(height: 10),
const Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.only(left: 17.0, bottom: 5.0),
child: Text(
'Password',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 15.0, top: 0.0, right: 15.0, bottom: 4.0),
child: TextFormField(
style: const TextStyle(color: Colors.black),
keyboardType: TextInputType.text,
controller: _passwordController,
onSaved: (input) {
_authData['password'] = input.toString();
_passwordController.text = input as String;
},
validator: (input) => input!.length < 3
? "Password should be more than 3 characters"
: null,
obscureText: hidePassword,
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
borderSide:
BorderSide(color: Colors.white, width: 2),
),
focusedBorder: const OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(12.0)),
borderSide:
BorderSide(color: Colors.white, width: 2),
),
border: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
borderRadius: BorderRadius.all(
Radius.circular(12.0),
),
),
filled: true,
hintStyle: const TextStyle(
color: Colors.black54, fontSize: 14),
hintText: "password",
fillColor: kBackgroundColor,
contentPadding: const EdgeInsets.symmetric(
vertical: 18, horizontal: 15),
prefixIcon: const Icon(
Icons.lock_outlined,
color: kTextLowBlackColor,
),
suffixIcon: IconButton(
onPressed: () {
setState(() {
hidePassword = !hidePassword;
});
},
color: kTextLowBlackColor,
icon: Icon(hidePassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined),
),
),
),
),
InkWell(
onTap: () {
Navigator.of(context)
.pushNamed(ForgotPassword.routeName);
},
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 20, vertical: 5),
child: Align(
alignment: Alignment.centerRight,
child: Text(
'Forget Password?',
style: TextStyle(color: kSecondaryColor),
),
),
),
),
SizedBox(
width: double.infinity,
child: _isLoading
? const Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.all(15.0),
child: MaterialButton(
elevation: 0,
color: kRedColor,
onPressed: _submit,
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 16),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadiusDirectional.circular(10),
// side: const BorderSide(color: kRedColor),
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: const [
Text(
'Log In',
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
),
const SizedBox(height: 20),
],
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Do not have an account?',
style: TextStyle(
color: kTextLowBlackColor,
fontSize: 15,
fontWeight: FontWeight.w400,
),
),
InkWell(
onTap: () {
Navigator.of(context).pushNamed(SignUpScreen.routeName);
},
child: const Text(
' Sign up',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
],
),
),
);
}
}
I am building a code on flutter, this is a login form and bellow this there is a text called Sign Up, I want to put external website url. Can anyone help me on this?
3
Answers
You can use RichText or just
Row[Text1,Text2ForSignUp]
If you mean that it should open a website in a browser then you can use the pub package url_launcher https://pub.dev/packages/url_launcher
And use it like so:
You can use url_launcher Package. url_launcher: ^6.1.14 https://pub.dev/packages/url_launcher
use launchUrl Method & pass url to this method