Skip to content

Commit

Permalink
feat: rework post sign up
Browse files Browse the repository at this point in the history
  • Loading branch information
inpt333 committed Dec 10, 2024
1 parent 33a9ec5 commit 9212127
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 65 deletions.
6 changes: 5 additions & 1 deletion lib/go_router_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ class LocaleRoute extends GoRouteData with AuthenticationGuard {

@immutable
class ProfileRoute extends GoRouteData with AuthenticationGuard {
final bool? userNavigated;

ProfileRoute({this.userNavigated});

@override
Widget build(BuildContext context, GoRouterState state) =>
const ProfileContainer();
ProfileContainer(userNavigated: userNavigated);
}

@immutable
Expand Down
29 changes: 28 additions & 1 deletion lib/go_router_builder.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/presentation/containers/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import 'package:redux/redux.dart';
part 'profile.freezed.dart';

class ProfileContainer extends StatelessWidget {
const ProfileContainer({super.key});
final bool? userNavigated;

const ProfileContainer({super.key, this.userNavigated});

@override
Widget build(BuildContext context) {
return StoreConnector(
builder: (context, vm) => ProfileScreen(
profile: vm.profile,
userNavigated: userNavigated,
onSave: vm.onSave,
),
converter: _ViewModel.fromStore,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class HomeScreen extends StatelessWidget {
: null,
actions: [
ProfilePicture(
onPressed: () => ProfileRoute().push(context),
onPressed: () => ProfileRoute(userNavigated: true).push(context),
image: _profilePicture(),
name: profile?.displayName,
),
Expand Down
119 changes: 66 additions & 53 deletions lib/presentation/screens/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ typedef OnProfileSaveCallback = ValueSetter<(String? name, XFile? image)>;

class ProfileScreen extends StatefulWidget {
final Profile? profile;
final bool? userNavigated;
final OnProfileSaveCallback onSave;

const ProfileScreen({super.key, this.profile, required this.onSave});
const ProfileScreen(
{super.key, this.profile, this.userNavigated, required this.onSave});

@override
createState() => _ProfileScreenState();
Expand All @@ -27,7 +29,7 @@ class _ProfileScreenState extends State<ProfileScreen> {

late TextEditingController _nameController;

bool _showSaveButton = false;
bool _enableSaveButton = false;
XFile? _tempImageFile;

@override
Expand Down Expand Up @@ -111,7 +113,7 @@ class _ProfileScreenState extends State<ProfileScreen> {

setState(() {
_tempImageFile = imageFile;
_showSaveButton = true;
_enableSaveButton = true;
});
}

Expand All @@ -133,60 +135,71 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
body: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
ProfilePicture(
onPressed: () => _changeImage(),
image: profilePicture,
name: _nameController.value.text,
radius: 64,
),
TextFormField(
focusNode: _nameFocusNode,
controller: _nameController,
decoration: InputDecoration(
labelText: l10n.enterYourName,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
ProfilePicture(
onPressed: () => _changeImage(),
image: profilePicture,
name: _nameController.value.text,
radius: 64,
),
TextFormField(
focusNode: _nameFocusNode,
controller: _nameController,
decoration: InputDecoration(
labelText: l10n.enterYourName,
),
validator: (value) {
if (value == null || value.isEmpty) {
return l10n.enterYourNamePlease;
}
return null;
},
onChanged: (value) {
setState(() {
if (_formKey.currentState!.validate()) {
_enableSaveButton = true;
} else {
_enableSaveButton = false;
}
});
},
),
// TODO(borgoat): options to link additional auth providers
],
),
validator: (value) {
if (value == null || value.isEmpty) {
return l10n.enterYourNamePlease;
}
return null;
},
onChanged: (value) {
setState(() {
if (_formKey.currentState!.validate()) {
_showSaveButton = true;
} else {
_showSaveButton = false;
}
});
},
),
// TODO(borgoat): options to link additional auth providers
],
),
),
Padding(
padding: const EdgeInsets.all(16),
child: FilledButton(
onPressed: _enableSaveButton
? () {
if (_formKey.currentState!.validate()) {
setState(() {
_enableSaveButton = false;
});
_formKey.currentState!.save();
_nameFocusNode.unfocus();
widget.onSave(
(_nameController.text.trim(), _tempImageFile));

if (!(widget.userNavigated ?? false)) {
Navigator.of(context).pop(context);
}
}
}
: null,
child: Text(l10n.save),
)),
],
),
),
floatingActionButton: _showSaveButton
? FloatingActionButton.extended(
onPressed: () {
if (_formKey.currentState!.validate()) {
setState(() {
_showSaveButton = false;
});
_formKey.currentState!.save();
_nameFocusNode.unfocus();
widget.onSave((_nameController.text.trim(), _tempImageFile));
}
},
label: Text(l10n.save),
icon: const Icon(Icons.check),
)
: null,
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}
13 changes: 5 additions & 8 deletions lib/presentation/widgets/group_join.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class _GroupJoinState extends State<GroupJoin> {
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: SingleChildScrollView(
Expand Down Expand Up @@ -76,13 +75,11 @@ class _GroupJoinState extends State<GroupJoin> {
child: ValueListenableBuilder(
valueListenable: _codeController,
builder: (context, value, child) => FilledButton(
onPressed: value.text.length == 9
? () {
if (_formKey.currentState!.validate()) {
widget.onJoin(_codeController.text);
}
}
: null,
onPressed: () {
if (_formKey.currentState!.validate()) {
widget.onJoin(_codeController.text);
}
},
child: Text(l10n.joinGroup),
),
),
Expand Down

0 comments on commit 9212127

Please sign in to comment.