Migrate away from helpers package

This commit is contained in:
2024-09-10 15:03:32 -06:00
parent ddba989576
commit 1172e650aa
19 changed files with 370 additions and 723 deletions
+11 -24
View File
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:helpers/helpers/misc_build/build_media.dart';
import 'package:helpers/helpers/print.dart';
import '../../global/api.dart';
import '../../global/styles.dart';
@@ -36,7 +34,7 @@ class _SignupState extends ConsumerState<Signup> {
@override
Widget build(BuildContext context) {
final screen = BuildMedia(context).size;
final screen = MediaQuery.of(context).size;
return Form(
key: widget.formKey,
child: Stack(
@@ -126,8 +124,7 @@ class _SignupState extends ConsumerState<Signup> {
),
UiButton(
width: screen.width * 0.4,
icon: const Icon(Icons.cancel,
color: Styles.washedStone, size: 20),
icon: const Icon(Icons.cancel, color: Styles.washedStone, size: 20),
onPressed: () {
setState(
() => hasFamilyCode = false,
@@ -140,9 +137,7 @@ class _SignupState extends ConsumerState<Signup> {
: Padding(
padding: const EdgeInsets.all(8.0),
child: UiButton(
width: screen.width * 0.5 > 400
? 400
: screen.width * 0.5,
width: screen.width * 0.5 > 400 ? 400 : screen.width * 0.5,
text: 'JOIN FAMILY',
// color: Styles.flounderBlue,
onPressed: () {
@@ -190,8 +185,7 @@ class _SignupState extends ConsumerState<Signup> {
text,
style: TextStyle(fontSize: size.width < 350 ? 16 : 20),
),
if (subtext != null)
Text(subtext, style: const TextStyle(fontSize: 12)),
if (subtext != null) Text(subtext, style: const TextStyle(fontSize: 12)),
],
),
),
@@ -223,36 +217,29 @@ class _SignupState extends ConsumerState<Signup> {
Future signup() async {
try {
if (widget.formKey.currentState != null &&
!widget.formKey.currentState!.validate()) {
if (widget.formKey.currentState != null && !widget.formKey.currentState!.validate()) {
return;
}
final data =
await ref.read(apiProvider.notifier).post(path: 'auth/signup', data: {
final data = await ref.read(apiProvider.notifier).post(path: 'auth/signup', data: {
'name': nameCotroller.text,
'username':
usernameController.text.isEmpty ? null : usernameController.text,
'username': usernameController.text.isEmpty ? null : usernameController.text,
'email': emailController.text.isEmpty ? null : emailController.text,
'password': passwordController.text,
'family_code': familyCodeController.text.isEmpty
? null
: familyCodeController.text.toUpperCase(),
'family_code': familyCodeController.text.isEmpty ? null : familyCodeController.text.toUpperCase(),
'budget_name': 'Budget'
});
final success = data?['success'] ?? false;
showSnack(
ref: ref,
text: data?['message'] ?? success
? 'Login successful'
: 'Login unsuccessful',
text: data?['message'] ?? success ? 'Login successful' : 'Login unsuccessful',
type: !success ? SnackType.error : SnackType.success);
printAmber(data);
print(data);
// final user = User.fromJson(data?['user']);
// ref.read(tokenProvider.notifier).state =
} catch (err) {
printRed(err);
print(err);
}
}
}