我目前正在努力使用go_router重构我的路由代码。
我已经得到了一些简单的路由,例如/signin& /signup,但是当我尝试使路由与具有多个屏幕的 BottomNavigationBar 一起工作时,问题就出现了。我想为他们每个人都有一条单独的路线,例如/home, /events& /profile。
我发现我必须以某种方式返回具有不同参数的相同小部件,以防止每当按下 BottomNavigationBarItem 时整个屏幕发生变化,而只更新 BottomNavigationBar 上方的部分(即屏幕本身)。
我想出了一个非常棘手的解决方案:
GoRoute(
path: '/:path',
builder: (BuildContext context, GoRouterState state) {
final String path = state.params['path']!;
if (path == 'signin') {
return const SignInScreen();
}
if (path == 'signup') {
return const SignUpScreen();
}
if (path == 'forgot-password') {
return const ForgotPasswordScreen();
}
// Otherwise it has to be the ScreenWithBottomBar
final int index = getIndexFromPath(path);
if (index != -1) …Run Code Online (Sandbox Code Playgroud) 目前,我正在刷新一个 FutureProvider,它负责从 Firebase 获取数据并将其显示在带有Liquid_pull_to_refresh包的简单 ListView 中,这会导致列表消失,加载指示器再次显示,最后列表再次显示。
我想要实现的是保持列表显示,并且仅在获取完成后更新它。我正在使用 Riverpod 进行状态管理。
提供者:
final userProfileProvider = FutureProvider.family<FullUserModel?, String?>((ref, value) => ref.read(databaseServiceProvider).getFullUserModel(value));
Run Code Online (Sandbox Code Playgroud)
刷新部分:
LiquidPullToRefresh(
onRefresh: () async {
ref.refresh(userProfileProvider(uid));
},
child: ListView()
)
Run Code Online (Sandbox Code Playgroud)
对此有什么好的方法吗?
我试图弄清楚如何利用 Firebase 的流作为go_router包中参数onAuthStateChanges()中的可监听对象,以便在 authState 更改时进行重定向。此外,我正在使用flutter_riverpod进行状态管理。refreshListenable
到目前为止我的代码看起来像这样:
我创建了一个简单的 AuthService 类(缩减到最重要的部分):
abstract class BaseAuthService {
Stream<bool> get isLoggedIn;
Future<bool> signInWithEmailAndPassword({ required String email, required String password });
}
class AuthService implements BaseAuthService {
final Reader _read;
const AuthService(this._read);
FirebaseAuth get auth => _read(firebaseAuthProvider);
@override
Stream<bool> get isLoggedIn => auth.authStateChanges().map((User? user) => user != null);
@override
Future<bool> signInWithEmailAndPassword({ required String email, required String password }) async {
try {
await auth.signInWithEmailAndPassword(email: email, password: password);
return true; …Run Code Online (Sandbox Code Playgroud)