login.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'dart:convert';
  2. // import 'package:date_format/date_format.dart';
  3. // import 'package:dio/dio.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6. // import 'package:go_router/go_router.dart';
  7. import 'package:namer_app/footer.dart';
  8. import 'package:namer_app/head.dart';
  9. // import 'package:namer_app/services/signIn.dart';
  10. // import 'package:namer_app/header.dart';
  11. class LoginPage extends StatelessWidget {
  12. const LoginPage({super.key});
  13. @override
  14. Widget build(BuildContext context) {
  15. // var dio = Dio();
  16. // Response response;
  17. final usernameController = TextEditingController();
  18. final passwordController = TextEditingController();
  19. // var auth =
  20. // 'Basic ${base64Encode(utf8.encode('$usernameController:$passwordController'))}';
  21. return Scaffold(
  22. // appBar: Header(
  23. // title: Text('title'),
  24. // appBar: AppBar(),
  25. // widgets: <Widget>[Icon(Icons.more_vert)],
  26. // ),
  27. appBar: CustomAppbar(),
  28. backgroundColor: Colors.white,
  29. body: Column(
  30. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  31. children: [
  32. Expanded(
  33. child: Center(
  34. child: Row(
  35. mainAxisAlignment: MainAxisAlignment.center,
  36. children: [
  37. Text(
  38. 'LOGIN',
  39. style: TextStyle(color: Colors.black, fontSize: 48),
  40. ),
  41. ],
  42. )),
  43. ),
  44. Expanded(
  45. child: Column(
  46. children: [
  47. Padding(
  48. padding: const EdgeInsets.all(8.0),
  49. child: SizedBox(
  50. width: 396,
  51. height: 51,
  52. child: TextField(
  53. decoration: InputDecoration(
  54. border: OutlineInputBorder(),
  55. focusedBorder: OutlineInputBorder(
  56. borderRadius: BorderRadius.all(Radius.circular(12)),
  57. borderSide: BorderSide(color: Colors.black)),
  58. enabledBorder: OutlineInputBorder(
  59. borderRadius: BorderRadius.all(Radius.circular(12)),
  60. borderSide: BorderSide(color: Colors.black)),
  61. labelText: 'Enter Username',
  62. labelStyle: TextStyle(color: Colors.black),
  63. filled: true,
  64. fillColor: Colors.white.withOpacity(0.25)),
  65. cursorColor: Colors.black,
  66. style: TextStyle(color: Colors.black),
  67. controller: usernameController,
  68. ),
  69. ),
  70. ),
  71. SizedBox(
  72. width: 396,
  73. height: 51,
  74. child: TextField(
  75. obscureText: true,
  76. decoration: InputDecoration(
  77. border: OutlineInputBorder(),
  78. focusedBorder: OutlineInputBorder(
  79. borderRadius: BorderRadius.all(Radius.circular(12)),
  80. borderSide: BorderSide(color: Colors.black)),
  81. enabledBorder: OutlineInputBorder(
  82. borderRadius: BorderRadius.all(Radius.circular(12)),
  83. borderSide: BorderSide(color: Colors.black)),
  84. labelText: 'Enter Password',
  85. labelStyle: TextStyle(color: Colors.black),
  86. filled: true,
  87. fillColor: Colors.white.withOpacity(0.25)),
  88. cursorColor: Colors.black,
  89. style: TextStyle(color: Colors.black),
  90. controller: passwordController,
  91. ),
  92. ),
  93. Padding(
  94. padding: const EdgeInsets.all(20.0),
  95. child: SizedBox(
  96. width: 396,
  97. height: 61,
  98. child: ElevatedButton(
  99. onPressed: () async{
  100. String basicAuth = 'Basic ${base64.encode('usernameController:passwordController' as List<int>)}';
  101. var response = await http.post(
  102. 'http://localhost:8080/api/v1' as Uri,
  103. headers: <String, String>{'authorization': basicAuth},
  104. );
  105. print('Response status: ${response.statusCode}');
  106. print('Response body: ${response.body}');
  107. },
  108. style: ElevatedButton.styleFrom(
  109. backgroundColor: Colors.black, //todo putih lage
  110. side: BorderSide(color: Colors.white),
  111. shape: RoundedRectangleBorder(
  112. borderRadius: BorderRadius.circular(12.0),
  113. ),
  114. ),
  115. child: Text(
  116. 'Login',
  117. style: TextStyle(color: Colors.white),
  118. ),
  119. ),
  120. ),
  121. ),
  122. ],
  123. )),
  124. ],
  125. ),
  126. bottomNavigationBar: Footer(),
  127. );
  128. }
  129. }