💄 Better bottom navigation

This commit is contained in:
2024-07-06 20:55:53 +08:00
parent a304b26c96
commit 66ddfea68d
9 changed files with 326 additions and 278 deletions

View File

@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:protocol_handler/protocol_handler.dart';
import 'package:solian/exts.dart';
import 'package:solian/providers/account.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
class SignInPopup extends StatefulWidget {
@ -13,13 +15,13 @@ class SignInPopup extends StatefulWidget {
State<SignInPopup> createState() => _SignInPopupState();
}
class _SignInPopupState extends State<SignInPopup> {
class _SignInPopupState extends State<SignInPopup> with ProtocolListener {
bool _isBusy = false;
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
void requestResetPassword(BuildContext context) async {
void requestResetPassword() async {
final username = _usernameController.value.text;
if (username.isEmpty) {
context.showErrorDialog('signinResetPasswordHint'.tr);
@ -49,7 +51,7 @@ class _SignInPopupState extends State<SignInPopup> {
context.showModalDialog('done'.tr, 'signinResetPasswordSent'.tr);
}
void performAction(BuildContext context) async {
void performAction() async {
final AuthProvider provider = Get.find();
final username = _usernameController.value.text;
@ -96,6 +98,27 @@ class _SignInPopupState extends State<SignInPopup> {
Navigator.pop(context, true);
}
@override
void initState() {
protocolHandler.addListener(this);
super.initState();
}
@override
void dispose() {
protocolHandler.removeListener(this);
super.dispose();
}
@override
void onProtocolUrlReceived(String url) {
final uri = url.replaceFirst('solink://', '');
if (uri == 'auth?status=done') {
closeInAppWebView();
performAction();
}
}
@override
Widget build(BuildContext context) {
return SizedBox(
@ -144,20 +167,19 @@ class _SignInPopupState extends State<SignInPopup> {
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
onSubmitted: (_) => performAction(context),
onSubmitted: (_) => performAction(),
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed:
_isBusy ? null : () => requestResetPassword(context),
onPressed: _isBusy ? null : () => requestResetPassword(),
style: TextButton.styleFrom(foregroundColor: Colors.grey),
child: Text('forgotPassword'.tr),
),
TextButton(
onPressed: _isBusy ? null : () => performAction(context),
onPressed: _isBusy ? null : () => performAction(),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [

View File

@ -12,14 +12,14 @@ import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/posts/post_list.dart';
class SocialScreen extends StatefulWidget {
const SocialScreen({super.key});
class FeedScreen extends StatefulWidget {
const FeedScreen({super.key});
@override
State<SocialScreen> createState() => _SocialScreenState();
State<FeedScreen> createState() => _FeedScreenState();
}
class _SocialScreenState extends State<SocialScreen> {
class _FeedScreenState extends State<FeedScreen> {
final PagingController<int, Post> _pagingController =
PagingController(firstPageKey: 0);
@ -52,26 +52,7 @@ class _SocialScreenState extends State<SocialScreen> {
@override
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
return Scaffold(
floatingActionButton: FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data == true) {
return FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () async {
final value =
await AppRouter.instance.pushNamed('postPublishing');
if (value != null) {
_pagingController.refresh();
}
},
);
}
return Container();
}),
body: Material(
color: Theme.of(context).colorScheme.surface,
child: RefreshIndicator(
@ -79,7 +60,7 @@ class _SocialScreenState extends State<SocialScreen> {
child: CustomScrollView(
slivers: [
SliverAppBar(
title: AppBarTitle('social'.tr),
title: AppBarTitle('feed'.tr),
centerTitle: false,
floating: true,
titleSpacing: SolianTheme.titleSpacing(context),
@ -87,6 +68,7 @@ class _SocialScreenState extends State<SocialScreen> {
actions: [
const BackgroundStateWidget(),
const NotificationButton(),
const FeedCreationButton(),
SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
),
@ -100,3 +82,26 @@ class _SocialScreenState extends State<SocialScreen> {
);
}
}
class FeedCreationButton extends StatelessWidget {
const FeedCreationButton({super.key});
@override
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
return FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data == true) {
return IconButton(
icon: const Icon(Icons.add_circle),
onPressed: () {
AppRouter.instance.pushNamed('postPublishing');
},
);
}
return const SizedBox();
});
}
}