首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用FlutterFire UI包而不显示appBar?

如何使用FlutterFire UI包而不显示appBar?
EN

Stack Overflow用户
提问于 2022-01-18 05:38:20
回答 1查看 535关注 0票数 0

我使用FlutterFire UI包进行身份验证,我使用屏幕,但是我想在不显示appBar的情况下显示Ui,有帮助吗?

ui包 ui文档

代码语言:javascript
运行
复制
return ProfileScreen(
      providerConfigs: [
        EmailProviderConfiguration(),
        GoogleProviderConfiguration(clientId: ''),
      ],
      avatarSize: 24,
    );
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-27 12:43:42

appBar在ProfileScreen小部件中是硬编码的,但是您可以很容易地复制ProfileScreen ->像项目中的CustomProfileScreen一样,并移除appBar。

示例:没有AppBar

代码语言:javascript
运行
复制
import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuth;
import 'package:flutter/cupertino.dart' hide Title;
import 'package:flutter/material.dart' hide Title;
import 'package:flutterfire_ui/auth.dart';
import 'package:flutterfire_ui/i10n.dart';

class CustomProfileScreen extends StatefulWidget {
  final List<ProviderConfiguration> providerConfigs;
  final List<Widget> children;
  final FirebaseAuth? auth;
  final Color? avatarPlaceholderColor;
  final ShapeBorder? avatarShape;
  final double? avatarSize;
  final List<FlutterFireUIAction>? actions;

  const CustomProfileScreen({
    Key? key,
    required this.providerConfigs,
    this.auth,
    this.avatarPlaceholderColor,
    this.avatarShape,
    this.avatarSize,
    this.children = const [],
    this.actions,
  }) : super(key: key);

  @override
  State<CustomProfileScreen> createState() => _CustomProfileScreenState();
}

class _CustomProfileScreenState extends State<CustomProfileScreen> {
  Future<void> _logout(BuildContext context) async {
    await (widget.auth ?? FirebaseAuth.instance).signOut();
    final action = FlutterFireUIAction.ofType<SignedOutAction>(context);

    action?.callback(context);
  }

  Future<bool> _reauthenticate(BuildContext context) {
    return showReauthenticateDialog(
      context: context,
      providerConfigs: widget.providerConfigs,
      auth: widget.auth,
      onSignedIn: () => Navigator.of(context).pop(true),
    );
  }

  @override
  Widget build(BuildContext context) {
    final l = FlutterFireUILocalizations.labelsOf(context);
    final isCupertino = CupertinoUserInterfaceLevel.maybeOf(context) != null;
    final platform = Theme.of(context).platform;
    final _auth = widget.auth ?? FirebaseAuth.instance;
    final _user = _auth.currentUser!;

    final linkedProviders = widget.providerConfigs
        .where((config) => _user.isProviderLinked(config.providerId))
        .toList();

    final availableProviders = widget.providerConfigs
        .where((config) => !_user.isProviderLinked(config.providerId))
        .where((config) => config.isSupportedPlatform(platform))
        .toList();

    final content = Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Align(
          child: UserAvatar(
            auth: widget.auth,
            placeholderColor: widget.avatarPlaceholderColor,
            shape: widget.avatarShape,
            size: widget.avatarSize,
          ),
        ),
        const SizedBox(height: 16),
        Align(child: EditableUserDisplayName(auth: widget.auth)),
        if (linkedProviders.isNotEmpty) ...[
          const SizedBox(height: 32),
          LinkedProvidersRow(
            auth: widget.auth,
            providerConfigs: linkedProviders,
          ),
        ],
        if (availableProviders.isNotEmpty) ...[
          const SizedBox(height: 32),
          AvailableProvidersRow(
            auth: widget.auth,
            providerConfigs: availableProviders,
            onProviderLinked: () => setState(() {}),
          ),
        ],
        ...widget.children,
        const SizedBox(height: 16),
        DeleteAccountButton(
          auth: widget.auth,
          onSignInRequired: () {
            return _reauthenticate(context);
          },
        ),
      ],
    );
    final body = Padding(
      padding: const EdgeInsets.all(16),
      child: Center(
        child: LayoutBuilder(
          builder: (context, constraints) {
            if (constraints.maxWidth > 500) {
              return ConstrainedBox(
                constraints: const BoxConstraints(maxWidth: 500),
                child: content,
              );
            } else {
              return content;
            }
          },
        ),
      ),
    );

    if (isCupertino) {
      return FlutterFireUIActions(
        actions: widget.actions ?? const [],
        child: Builder(
          builder: (context) => CupertinoPageScaffold(
            child: SafeArea(child: SingleChildScrollView(child: body)),
          ),
        ),
      );
    } else {
      return FlutterFireUIActions(
        actions: widget.actions ?? const [],
        child: Builder(
          builder: (context) => Scaffold(
            body: SafeArea(child: SingleChildScrollView(child: body)),
          ),
        ),
      );
    }
  }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70750749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档