Line data Source code
1 : import 'package:flutter/material.dart';
2 :
3 : import '../../../shared/widgets/stretchable_button.dart';
4 :
5 : const double defaultBorderRadius = 3.0;
6 :
7 25 : enum AppleButtonStyle { white, whiteOutline, black }
8 :
9 : /// A sign in button that matches Apple's design guidelines.
10 : class AppleSignInButton extends StatelessWidget {
11 : final String text;
12 : final AppleButtonStyle style;
13 : final double borderRadius;
14 : final VoidCallback? onPressed;
15 : final TextStyle? textStyle;
16 : final Color? splashColor;
17 : final bool centered;
18 :
19 : /// Creates a new button. Set [darkMode] to `true` to use the dark
20 : /// black background variant with white text, otherwise an all-white background
21 : /// with dark text is used.
22 0 : const AppleSignInButton(
23 : {this.onPressed,
24 : // 'Continue with Apple' is also an available variant depdening on App's sign-in experience.
25 : this.text = 'Sign in with Apple',
26 : this.textStyle,
27 : this.splashColor,
28 : this.style = AppleButtonStyle.white,
29 : // Apple doesn't specify a border radius, but this looks about right.
30 : this.borderRadius = defaultBorderRadius,
31 : this.centered = false,
32 : Key? key})
33 0 : : super(key: key);
34 :
35 0 : @override
36 : Widget build(BuildContext context) {
37 0 : return StretchableButton(
38 : buttonColor:
39 0 : style == AppleButtonStyle.black ? Colors.black : Colors.white,
40 0 : borderRadius: borderRadius,
41 0 : splashColor: splashColor,
42 : buttonBorderColor:
43 0 : style == AppleButtonStyle.whiteOutline ? Colors.black : null,
44 0 : onPressed: onPressed,
45 : buttonPadding: 0.0,
46 0 : centered: centered,
47 0 : children: <Widget>[
48 0 : Center(
49 0 : child: Row(
50 0 : children: <Widget>[
51 0 : Padding(
52 : padding: const EdgeInsets.only(left: 22.0, bottom: 3.0),
53 0 : child: Container(
54 : height: 38.0,
55 : width: 32.0,
56 0 : decoration: BoxDecoration(
57 0 : borderRadius: BorderRadius.circular(borderRadius),
58 : ),
59 0 : child: Center(
60 0 : child: Image(
61 0 : image: AssetImage(
62 0 : "assets/apple_${style == AppleButtonStyle.black ? "white" : "black"}.png",
63 : package: 'redfire'),
64 : height: 17.0,
65 : width: 17.0,
66 : ),
67 : ),
68 : ),
69 : ),
70 0 : Padding(
71 : padding: const EdgeInsets.fromLTRB(0.0, 8.0, 32.0, 8.0),
72 0 : child: Text(
73 0 : text,
74 0 : style: textStyle ??
75 0 : TextStyle(
76 : fontSize: 16.0,
77 : fontFamily: 'SF Pro',
78 : fontWeight: FontWeight.w500,
79 0 : color: style == AppleButtonStyle.black
80 : ? Colors.white
81 : : Colors.black,
82 : ),
83 : ),
84 : ),
85 : ],
86 : ),
87 : )
88 : ],
89 : );
90 : }
91 : }
|