最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Flutter with Clerk -- "No `ClerkAuth` found in context" - Stack Overflow

programmeradmin1浏览0评论

I'm using clerk_flutter: ^0.0.8-beta authentication for the app I'm building. What I'm trying to do is simple: sign up a user, and display a homepage if successful.

Here's the main.dart file:

import 'package:app_frontend/example.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter App',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const ExampleApp(
        publishableKey:
        "**clerk_publishable_key_here**",
      ),
    );
  }
}

And here's the example.dart file, slightly modified from the one in pub.dev

import 'package:clerk_flutter/clerk_flutter.dart';
import 'package:flutter/material.dart';

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key, required this.publishableKey});

  final String publishableKey;

  @override
  Widget build(BuildContext context) {
    return ClerkAuth(
      config: ClerkAuthConfig(publishableKey: publishableKey),
      child: SafeArea(
        child: ClerkErrorListener(
          child: ClerkAuthBuilder(
            signedInBuilder: (context, authState) {
              return const Center(
                child: Text("Homepage"),
              );
            },
            signedOutBuilder: (context, authState) {
              return const ClerkAuthentication();
            },
          ),
        ),
      ),
    );
  }
}

I've got the flutter signup widget on my device, but when I try to sign up with Google, I get the following error in Android Studio:

======== Exception caught by widgets library ======================================================= The following assertion was thrown building Builder: No 'ClerkAuth' found in context 'package:clerk_flutter/src/widgets/control/clerk_auth.dart': Failed assertion: line 56 pos 12: 'result != null'

I thought at first it may have been caused by me stacking the Clerk and main.dart file's MaterialApp widget. That wasn't it. I haven't found too many examples done with this package except the one from pub.dev.

I also inspected the ClerkAuth and ClerkAuthState objects in the documentation, but I couldn't solve my problem. Anyone who can better understand the documentation?

发布评论

评论列表(0)

  1. 暂无评论