fix: fixing nulable return from verif auth
This commit is contained in:
parent
2ac0e09309
commit
4af31d867e
|
@ -12,10 +12,9 @@ void main() async {
|
||||||
await dotenv.load(fileName: "server/.env.dev");
|
await dotenv.load(fileName: "server/.env.dev");
|
||||||
HttpOverrides.global = MyHttpOverrides();
|
HttpOverrides.global = MyHttpOverrides();
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await initializeDateFormatting(
|
await initializeDateFormatting('id_ID', null).then((_) {
|
||||||
'id_ID',
|
runApp(const MyApp());
|
||||||
null,
|
});
|
||||||
).then((_) => runApp(const MyApp()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
|
@ -23,15 +22,16 @@ class MyApp extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ScreenUtilInit(
|
return ChangeNotifierProvider(
|
||||||
|
create: (_) => AuthViewModel(),
|
||||||
|
child: ScreenUtilInit(
|
||||||
designSize: const Size(375, 812),
|
designSize: const Size(375, 812),
|
||||||
builder:
|
builder: (_, child) {
|
||||||
(_, child) => ChangeNotifierProvider(
|
return MaterialApp.router(
|
||||||
create: (_) => UserViewModel(),
|
|
||||||
child: MaterialApp.router(
|
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
routerConfig: router,
|
routerConfig: router,
|
||||||
),
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:rijig_mobile/core/api_services.dart';
|
||||||
|
|
||||||
class AuthModel {
|
class AuthModel {
|
||||||
final int status;
|
final int status;
|
||||||
final String message;
|
final String message;
|
||||||
|
@ -6,8 +8,35 @@ class AuthModel {
|
||||||
|
|
||||||
factory AuthModel.fromJson(Map<String, dynamic> json) {
|
factory AuthModel.fromJson(Map<String, dynamic> json) {
|
||||||
return AuthModel(
|
return AuthModel(
|
||||||
status: json['meta']['status'],
|
status: json['meta']?['status'] ?? 0,
|
||||||
message: json['meta']['message'],
|
message: json['meta']?['message'] ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AuthService {
|
||||||
|
final ApiService _apiService = ApiService();
|
||||||
|
|
||||||
|
Future<AuthModel?> login(String phone) async {
|
||||||
|
try {
|
||||||
|
var response = await _apiService.post('/authmasyarakat/auth', {
|
||||||
|
'phone': phone,
|
||||||
|
});
|
||||||
|
return AuthModel.fromJson(response);
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> verifyOtp(String phone, String otp) async {
|
||||||
|
try {
|
||||||
|
var response = await _apiService.post('/authmasyarakat/verify-otp', {
|
||||||
|
'phone': phone,
|
||||||
|
'otp': otp,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:rijig_mobile/core/router.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class ProfilScreen extends StatefulWidget {
|
class ProfilScreen extends StatefulWidget {
|
||||||
const ProfilScreen({super.key});
|
const ProfilScreen({super.key});
|
||||||
|
@ -12,7 +14,22 @@ class _ProfilScreenState extends State<ProfilScreen> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final titleofscreen = "Profil";
|
final titleofscreen = "Profil";
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Center(child: Text("ini adalah halaman $titleofscreen")),
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text("ini adalah halaman $titleofscreen"),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.remove('isLoggedIn');
|
||||||
|
router.go('/login');
|
||||||
|
},
|
||||||
|
child: Text("keluar"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:rijig_mobile/core/guide.dart';
|
||||||
import 'package:rijig_mobile/core/router.dart';
|
import 'package:rijig_mobile/core/router.dart';
|
||||||
import 'package:rijig_mobile/viewmodel/auth_vmod.dart';
|
import 'package:rijig_mobile/viewmodel/auth_vmod.dart';
|
||||||
|
import 'package:rijig_mobile/widget/buttoncard.dart';
|
||||||
|
import 'package:rijig_mobile/widget/formfiled.dart';
|
||||||
|
|
||||||
class LoginScreen extends StatelessWidget {
|
class LoginScreen extends StatelessWidget {
|
||||||
final _phoneController = TextEditingController();
|
final _phoneController = TextEditingController();
|
||||||
|
@ -11,10 +14,10 @@ class LoginScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text('Login')),
|
body: SafeArea(
|
||||||
body: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: PaddingCustom().paddingHorizontalVertical(15, 30),
|
||||||
child: Consumer<UserViewModel>(
|
child: Consumer<AuthViewModel>(
|
||||||
builder: (context, userVM, child) {
|
builder: (context, userVM, child) {
|
||||||
if (userVM.authModel?.status == 200) {
|
if (userVM.authModel?.status == 200) {
|
||||||
Future.delayed(Duration.zero, () {
|
Future.delayed(Duration.zero, () {
|
||||||
|
@ -25,25 +28,34 @@ class LoginScreen extends StatelessWidget {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
TextField(
|
FormFieldOne(
|
||||||
controller: _phoneController,
|
controllers: _phoneController,
|
||||||
|
hintText: 'Phone Number',
|
||||||
|
isRequired: true,
|
||||||
|
onTap: () {},
|
||||||
keyboardType: TextInputType.phone,
|
keyboardType: TextInputType.phone,
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Phone Number',
|
|
||||||
errorText: userVM.errorMessage,
|
errorText: userVM.errorMessage,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
|
||||||
userVM.isLoading
|
userVM.isLoading
|
||||||
? CircularProgressIndicator()
|
? CircularProgressIndicator()
|
||||||
: ElevatedButton(
|
: CardButtonOne(
|
||||||
onPressed: () {
|
textButton: 'Send OTP',
|
||||||
|
fontSized: 16,
|
||||||
|
colorText: Colors.white,
|
||||||
|
borderRadius: 12,
|
||||||
|
horizontal: double.infinity,
|
||||||
|
vertical: 50,
|
||||||
|
onTap: () {
|
||||||
if (_phoneController.text.isNotEmpty) {
|
if (_phoneController.text.isNotEmpty) {
|
||||||
userVM.login(_phoneController.text);
|
userVM.login(_phoneController.text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text('Send OTP'),
|
loadingTrue: userVM.isLoading,
|
||||||
|
usingRow: false,
|
||||||
),
|
),
|
||||||
|
|
||||||
if (userVM.authModel != null)
|
if (userVM.authModel != null)
|
||||||
Text(
|
Text(
|
||||||
userVM.authModel!.message,
|
userVM.authModel!.message,
|
||||||
|
@ -59,6 +71,7 @@ class LoginScreen extends StatelessWidget {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +1,80 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pin_code_fields/pin_code_fields.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:rijig_mobile/core/router.dart';
|
import 'package:rijig_mobile/core/router.dart';
|
||||||
import 'package:rijig_mobile/viewmodel/auth_vmod.dart';
|
import 'package:rijig_mobile/viewmodel/auth_vmod.dart';
|
||||||
|
import 'package:rijig_mobile/widget/buttoncard.dart';
|
||||||
|
|
||||||
class VerifotpScreen extends StatelessWidget {
|
class VerifotpScreen extends StatefulWidget {
|
||||||
final String phone;
|
final dynamic phone;
|
||||||
|
|
||||||
|
const VerifotpScreen({super.key, required this.phone});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<VerifotpScreen> createState() => _VerifotpScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _VerifotpScreenState extends State<VerifotpScreen> {
|
||||||
final _otpController = TextEditingController();
|
final _otpController = TextEditingController();
|
||||||
|
|
||||||
VerifotpScreen({super.key, required this.phone});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final viewModel = Provider.of<AuthViewModel>(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text('Verify OTP')),
|
body: SafeArea(
|
||||||
body: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: EdgeInsets.all(16.0),
|
||||||
child: Consumer<UserViewModel>(
|
child: Column(
|
||||||
builder: (context, userVM, child) {
|
|
||||||
if (userVM.isLoading) {
|
|
||||||
return Center(child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text('Phone: $phone', style: TextStyle(fontSize: 18)),
|
Text('Phone: ${widget.phone}', style: TextStyle(fontSize: 18)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
|
||||||
TextField(
|
PinCodeTextField(
|
||||||
controller: _otpController,
|
controller: _otpController,
|
||||||
|
length: 4,
|
||||||
|
onChanged: (value) {},
|
||||||
|
appContext: context,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
autoFocus: true,
|
||||||
labelText: 'Enter OTP',
|
pinTheme: PinTheme(
|
||||||
errorText: userVM.errorMessage,
|
shape: PinCodeFieldShape.box,
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
fieldHeight: 50,
|
||||||
|
fieldWidth: 50,
|
||||||
|
inactiveColor: Colors.black54,
|
||||||
|
activeColor: Colors.blue,
|
||||||
|
selectedColor: Colors.blue,
|
||||||
),
|
),
|
||||||
|
animationType: AnimationType.fade,
|
||||||
|
textStyle: TextStyle(fontSize: 20, color: Colors.black),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
ElevatedButton(
|
CardButtonOne(
|
||||||
onPressed: () async {
|
textButton: 'Verify OTP',
|
||||||
String otp = _otpController.text;
|
fontSized: 16,
|
||||||
|
colorText: Colors.white,
|
||||||
if (otp.isNotEmpty) {
|
borderRadius: 12,
|
||||||
await Future.delayed(Duration(milliseconds: 50));
|
horizontal: double.infinity,
|
||||||
userVM.verifyOtp(phone, otp);
|
vertical: 50,
|
||||||
|
onTap: () {
|
||||||
if (userVM.authModel?.status == 200) {
|
if (_otpController.text.isNotEmpty) {
|
||||||
debugPrint("routing ke halaman home");
|
viewModel.verifyOtp(widget.phone, _otpController.text).then(
|
||||||
|
(_) {
|
||||||
|
if (viewModel.errorMessage == null) {
|
||||||
router.go('/navigasi');
|
router.go('/navigasi');
|
||||||
}
|
} else {
|
||||||
|
debugPrint(viewModel.errorMessage ?? '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text('Verify OTP'),
|
);
|
||||||
),
|
}
|
||||||
|
},
|
||||||
if (userVM.errorMessage != null)
|
loadingTrue: viewModel.isLoading,
|
||||||
Text(
|
usingRow: false,
|
||||||
userVM.errorMessage!,
|
|
||||||
style: TextStyle(color: Colors.red),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rijig_mobile/core/api_services.dart';
|
|
||||||
import 'package:rijig_mobile/model/auth_model.dart';
|
import 'package:rijig_mobile/model/auth_model.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class UserViewModel extends ChangeNotifier {
|
class AuthViewModel extends ChangeNotifier {
|
||||||
final ApiService _apiService = ApiService();
|
final AuthService _authService = AuthService();
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
String? errorMessage;
|
String? errorMessage;
|
||||||
AuthModel? authModel;
|
AuthModel? authModel;
|
||||||
|
@ -15,22 +14,13 @@ class UserViewModel extends ChangeNotifier {
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
var response = await _apiService.post('/authmasyarakat/auth', {
|
authModel = await _authService.login(phone);
|
||||||
'phone': phone,
|
|
||||||
});
|
|
||||||
|
|
||||||
authModel = AuthModel.fromJson(response);
|
if (authModel?.status != 200) {
|
||||||
|
|
||||||
if (authModel?.status == 200) {
|
|
||||||
} else {
|
|
||||||
errorMessage = authModel?.message ?? 'Failed to send OTP';
|
errorMessage = authModel?.message ?? 'Failed to send OTP';
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e is NetworkException) {
|
errorMessage = 'Error: $e';
|
||||||
errorMessage = e.message;
|
|
||||||
} else {
|
|
||||||
errorMessage = 'Something went wrong. Please try again later.';
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -43,28 +33,21 @@ class UserViewModel extends ChangeNotifier {
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
var response = await _apiService.post('/authmasyarakat/verify-otp', {
|
var response = await _authService.verifyOtp(phone, otp);
|
||||||
'phone': phone,
|
|
||||||
'otp': otp,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response['meta']['status'] == 200) {
|
if (response['meta'] != null && response['meta']['status'] == 200) {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.setString('token', response['data']['token']);
|
await prefs.setString('token', response['data']['token']);
|
||||||
await prefs.setString('user_id', response['data']['user_id']);
|
await prefs.setString('user_id', response['data']['user_id']);
|
||||||
await prefs.setString('user_role', response['data']['user_role']);
|
await prefs.setString('user_role', response['data']['user_role']);
|
||||||
await prefs.setBool('isLoggedIn', true);
|
await prefs.setBool('isLoggedIn', true);
|
||||||
|
|
||||||
debugPrint("berhasil login");
|
authModel = AuthModel.fromJson(response['data']);
|
||||||
} else {
|
} else {
|
||||||
errorMessage = response['meta']['message'] ?? 'Failed to verify OTP';
|
errorMessage = response['meta']?['message'] ?? 'Failed to verify OTP';
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e is NetworkException) {
|
errorMessage = 'Error: $e';
|
||||||
errorMessage = e.message;
|
|
||||||
} else {
|
|
||||||
errorMessage = 'Something went wrong. Please try again later.';
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:rijig_mobile/core/guide.dart';
|
||||||
|
|
||||||
|
class CardButtonOne extends StatelessWidget {
|
||||||
|
final String textButton;
|
||||||
|
final double fontSized;
|
||||||
|
final Color colorText;
|
||||||
|
final double borderRadius;
|
||||||
|
final double horizontal;
|
||||||
|
final double vertical;
|
||||||
|
final Function() onTap;
|
||||||
|
final Color? color;
|
||||||
|
final BoxBorder? borderAll;
|
||||||
|
final bool loadingTrue;
|
||||||
|
final bool usingRow;
|
||||||
|
final MainAxisSize mainAxisSize;
|
||||||
|
final Widget? child;
|
||||||
|
const CardButtonOne({
|
||||||
|
super.key,
|
||||||
|
required this.textButton,
|
||||||
|
required this.fontSized,
|
||||||
|
required this.colorText,
|
||||||
|
required this.borderRadius,
|
||||||
|
required this.horizontal,
|
||||||
|
required this.vertical,
|
||||||
|
required this.onTap,
|
||||||
|
this.loadingTrue = false,
|
||||||
|
this.usingRow = false,
|
||||||
|
this.color,
|
||||||
|
this.borderAll,
|
||||||
|
this.mainAxisSize = MainAxisSize.max,
|
||||||
|
this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
height: vertical,
|
||||||
|
width: horizontal,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: color ?? blackNavyColor,
|
||||||
|
borderRadius: BorderRadius.circular(borderRadius).w,
|
||||||
|
border: borderAll,
|
||||||
|
),
|
||||||
|
margin: EdgeInsets.zero,
|
||||||
|
child: Center(
|
||||||
|
child:
|
||||||
|
(!loadingTrue)
|
||||||
|
? usingRow == false
|
||||||
|
? Text(
|
||||||
|
textButton,
|
||||||
|
style: GoogleFonts.roboto(
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontWeight: bold,
|
||||||
|
fontSize: fontSized.sp,
|
||||||
|
color: colorText,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Row(
|
||||||
|
mainAxisSize: mainAxisSize,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
textButton,
|
||||||
|
style: GoogleFonts.roboto(
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontWeight: medium,
|
||||||
|
fontSize: fontSized.sp,
|
||||||
|
color: colorText,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GapCustom().gapValue(10, false),
|
||||||
|
Container(child: child),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: CircularProgressIndicator(
|
||||||
|
backgroundColor: whiteColor,
|
||||||
|
color: primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,256 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:rijig_mobile/core/guide.dart';
|
||||||
|
|
||||||
|
class FormFieldOne extends StatefulWidget {
|
||||||
|
const FormFieldOne({
|
||||||
|
super.key,
|
||||||
|
this.fontSize,
|
||||||
|
this.fontSizeField,
|
||||||
|
this.controllers,
|
||||||
|
this.hintText = '',
|
||||||
|
this.enabled = true,
|
||||||
|
required this.isRequired,
|
||||||
|
this.maxLines = 1,
|
||||||
|
this.minLines = 1,
|
||||||
|
this.keyboardType = TextInputType.text,
|
||||||
|
this.textInputAction = TextInputAction.next,
|
||||||
|
this.prefixIcon,
|
||||||
|
this.prefix,
|
||||||
|
this.errorText,
|
||||||
|
this.errorTextWidget,
|
||||||
|
this.suffixIcon,
|
||||||
|
this.inputColor,
|
||||||
|
this.textColor,
|
||||||
|
this.isObsecure = false,
|
||||||
|
this.isHasHint = true,
|
||||||
|
this.isPrice = false,
|
||||||
|
this.placeholder,
|
||||||
|
this.onChangeText,
|
||||||
|
required this.onTap,
|
||||||
|
this.isHandOver = false,
|
||||||
|
this.focusNode,
|
||||||
|
this.borderColor,
|
||||||
|
this.onEditingComplete,
|
||||||
|
this.hintTextStyle,
|
||||||
|
this.hintTextBoxFieldStyle,
|
||||||
|
this.typeFormat,
|
||||||
|
this.onChanged,
|
||||||
|
this.scrollPadding = const EdgeInsets.all(0),
|
||||||
|
this.onFieldSubmitted,
|
||||||
|
this.validator,
|
||||||
|
this.readOnly = false,
|
||||||
|
this.controllerTextStyle,
|
||||||
|
this.maxLength,
|
||||||
|
this.onFocus = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final void Function(String)? onChanged;
|
||||||
|
final TextEditingController? controllers;
|
||||||
|
final double? fontSize;
|
||||||
|
final double? fontSizeField;
|
||||||
|
final String hintText;
|
||||||
|
final String? placeholder;
|
||||||
|
final bool enabled;
|
||||||
|
final bool readOnly;
|
||||||
|
final bool isRequired;
|
||||||
|
final bool isObsecure;
|
||||||
|
final bool isHasHint;
|
||||||
|
final bool isPrice;
|
||||||
|
final bool isHandOver;
|
||||||
|
final int maxLines;
|
||||||
|
final int minLines;
|
||||||
|
final String? typeFormat;
|
||||||
|
final FocusNode? focusNode;
|
||||||
|
final TextInputAction textInputAction;
|
||||||
|
final TextInputType keyboardType;
|
||||||
|
final EdgeInsets scrollPadding;
|
||||||
|
final Widget? prefixIcon;
|
||||||
|
final Widget? prefix;
|
||||||
|
final String? errorText;
|
||||||
|
final Widget? suffixIcon;
|
||||||
|
final Widget? errorTextWidget;
|
||||||
|
final Color? inputColor;
|
||||||
|
final Color? borderColor;
|
||||||
|
final Color? textColor;
|
||||||
|
final Function? onChangeText;
|
||||||
|
final Function onTap;
|
||||||
|
final Function? onEditingComplete;
|
||||||
|
final TextStyle? hintTextStyle;
|
||||||
|
final TextStyle? hintTextBoxFieldStyle;
|
||||||
|
final TextStyle? controllerTextStyle;
|
||||||
|
final Function(String)? onFieldSubmitted;
|
||||||
|
final FormFieldValidator<String>? validator;
|
||||||
|
final int? maxLength;
|
||||||
|
final bool onFocus;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FormFieldOne> createState() => _FormFieldOneState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FormFieldOneState extends State<FormFieldOne> {
|
||||||
|
late FocusNode _focusNode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_focusNode =
|
||||||
|
widget.isRequired ? (widget.focusNode ?? FocusNode()) : FocusNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (widget.controllers != null) {
|
||||||
|
widget.controllers?.dispose();
|
||||||
|
}
|
||||||
|
_focusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
if (widget.isHasHint)
|
||||||
|
widget.isHasHint == true &&
|
||||||
|
widget.isRequired == true &&
|
||||||
|
widget.hintText != ''
|
||||||
|
? Container(
|
||||||
|
margin: const EdgeInsets.fromLTRB(0, 12, 16, 4),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: RichText(
|
||||||
|
text: TextSpan(
|
||||||
|
style: GoogleFonts.dmSans(
|
||||||
|
fontSize: widget.fontSize ?? 14.sp,
|
||||||
|
color: blackNavyColor,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: widget.hintText,
|
||||||
|
style: widget.hintTextStyle,
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text: '\t*',
|
||||||
|
style: GoogleFonts.dmSans(color: redColor),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: widget.isHasHint && widget.hintText != ''
|
||||||
|
? Container(
|
||||||
|
padding: PaddingCustom().paddingOnly(
|
||||||
|
left: 0,
|
||||||
|
top: 12,
|
||||||
|
bottom: 4,
|
||||||
|
),
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Text(widget.hintText, style: widget.hintTextStyle),
|
||||||
|
)
|
||||||
|
: const SizedBox(height: 8),
|
||||||
|
Card(
|
||||||
|
margin: const EdgeInsets.all(0.0),
|
||||||
|
elevation: 0,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: TextFormField(
|
||||||
|
readOnly: widget.readOnly,
|
||||||
|
scrollPadding: widget.scrollPadding,
|
||||||
|
minLines: widget.minLines,
|
||||||
|
textInputAction: widget.textInputAction,
|
||||||
|
focusNode: _focusNode,
|
||||||
|
onFieldSubmitted: widget.onFieldSubmitted,
|
||||||
|
controller: widget.controllers,
|
||||||
|
onChanged: widget.onChanged,
|
||||||
|
maxLength: widget.maxLength,
|
||||||
|
onTap: () {
|
||||||
|
widget.onTap();
|
||||||
|
},
|
||||||
|
onEditingComplete:
|
||||||
|
widget.onEditingComplete != null
|
||||||
|
? () {
|
||||||
|
widget.onEditingComplete!();
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
enabled: widget.enabled,
|
||||||
|
obscureText: widget.isObsecure,
|
||||||
|
style:
|
||||||
|
widget.controllerTextStyle ??
|
||||||
|
GoogleFonts.dmSans(
|
||||||
|
fontSize: widget.fontSizeField ?? 12.sp,
|
||||||
|
fontWeight: regular,
|
||||||
|
color:
|
||||||
|
widget.textColor ??
|
||||||
|
(widget.enabled ? Colors.black : Colors.black54),
|
||||||
|
),
|
||||||
|
keyboardType: widget.keyboardType,
|
||||||
|
maxLines: widget.maxLines,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
isDense: true,
|
||||||
|
fillColor: widget.inputColor ?? whiteColor,
|
||||||
|
filled: true,
|
||||||
|
hintText: widget.placeholder ?? 'Masukan ${widget.hintText}',
|
||||||
|
hintStyle:
|
||||||
|
widget.hintTextBoxFieldStyle ??
|
||||||
|
GoogleFonts.dmSans(
|
||||||
|
fontSize: widget.fontSize ?? 14.sp,
|
||||||
|
fontWeight: regular,
|
||||||
|
color:
|
||||||
|
widget.textColor ??
|
||||||
|
(widget.enabled ? Colors.black54 : Colors.black38),
|
||||||
|
),
|
||||||
|
prefixIcon: widget.prefixIcon,
|
||||||
|
prefix: widget.prefix,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
borderSide: BorderSide(color: blackNavyColor, width: 0.5),
|
||||||
|
),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: widget.borderColor ?? blackNavyColor,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
disabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
borderSide: BorderSide(color: blackNavyColor, width: 0.5),
|
||||||
|
),
|
||||||
|
focusedBorder:
|
||||||
|
widget.isRequired
|
||||||
|
? OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
borderSide: BorderSide(color: primaryColor, width: 0.5),
|
||||||
|
)
|
||||||
|
: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: blackNavyColor,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
suffixIcon: widget.suffixIcon,
|
||||||
|
),
|
||||||
|
validator:
|
||||||
|
widget.validator ??
|
||||||
|
(value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Please enter some text';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -344,6 +344,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.0"
|
version: "6.1.0"
|
||||||
|
pin_code_fields:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: pin_code_fields
|
||||||
|
sha256: "4c0db7fbc889e622e7c71ea54b9ee624bb70c7365b532abea0271b17ea75b729"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "8.0.1"
|
||||||
platform:
|
platform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -21,6 +21,7 @@ dependencies:
|
||||||
http: ^1.3.0
|
http: ^1.3.0
|
||||||
iconsax_flutter: ^1.0.0
|
iconsax_flutter: ^1.0.0
|
||||||
intl: ^0.20.2
|
intl: ^0.20.2
|
||||||
|
pin_code_fields: ^8.0.1
|
||||||
provider: ^6.1.4
|
provider: ^6.1.4
|
||||||
shared_preferences: ^2.3.3
|
shared_preferences: ^2.3.3
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue