美文网首页
Flutter三方库介绍和梳理

Flutter三方库介绍和梳理

作者: Mr姜饼 | 来源:发表于2022-03-03 15:11 被阅读0次

    1.path_provider
    用于查找文件系统上常用位置的Flutter插件。 支持Android、iOS、Linux、macOS和Windows。 并非所有平台都支持所有方法

    example:
    Directory tempDir = await getTemporaryDirectory();
    String tempPath = tempDir.path;
    
    Directory appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;
    
    image.png

    2.flutter_slidable
    具有可撤销的定向滑动动作的可滑动列表项的颤振实现。

    example
    Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Slidable Example',
          home: Scaffold(
            body: ListView(
              children: [
                Slidable(
                  // Specify a key if the Slidable is dismissible.
                  key: const ValueKey(0),
    
                  // The start action pane is the one at the left or the top side.
                  startActionPane: ActionPane(
                    // A motion is a widget used to control how the pane animates.
                    motion: const ScrollMotion(),
    
                    // A pane can dismiss the Slidable.
                    dismissible: DismissiblePane(onDismissed: () {}),
    
                    // All actions are defined in the children parameter.
                    children:  [
                      // A SlidableAction can have an icon and/or a label.
                      SlidableAction(
                        onPressed: (BuildContext context){
                          print('Delete');
                        },
                        backgroundColor: Color(0xFFFE4A49),
                        foregroundColor: Colors.white,
                        icon: Icons.delete,
                        label: 'Delete',
                      ),
                      SlidableAction(
                        onPressed: (BuildContext context){
                          print('Share');
                        },
                        backgroundColor: Color(0xFF21B7CA),
                        foregroundColor: Colors.white,
                        icon: Icons.share,
                        label: 'Share',
                      ),
                    ],
                  ),
    
                  // The end action pane is the one at the right or the bottom side.
                  endActionPane:  ActionPane(
                    motion: ScrollMotion(),
                    children: [
                      SlidableAction(
                        // An action can be bigger than the others.
                        flex: 2,
                        onPressed: (BuildContext context){
                          print('archive');
                        },
                        backgroundColor: Color(0xFF7BC043),
                        foregroundColor: Colors.white,
                        icon: Icons.archive,
                        label: 'Archive',
                      ),
                      SlidableAction(
                        onPressed: (BuildContext context){
                          print('save');
                        },
                        backgroundColor: Color(0xFF0392CF),
                        foregroundColor: Colors.white,
                        icon: Icons.save,
                        label: 'Save',
                      ),
                    ],
                  ),
    
                  // The child of the Slidable is what the user sees when the
                  // component is not dragged.
                  child: const ListTile(title: Text('Slide me')),
                ),
              ],
            ),
          ),
        );
      }
    
    image.png

    3.sign_in_with_apple
    Flutter bridge to Sign in with Apple. Supports login via an Apple ID, as well as retrieving credentials saved in the user's keychain.

    example
    class _MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Example app: Sign in with Apple'),
            ),
            body: Container(
              padding: const EdgeInsets.all(10),
              child: Center(
                child: SignInWithAppleButton(
                  onPressed: () async {
                    final credential = await SignInWithApple.getAppleIDCredential(
                      scopes: [
                        AppleIDAuthorizationScopes.email,
                        AppleIDAuthorizationScopes.fullName,
                      ],
                      webAuthenticationOptions: WebAuthenticationOptions(
                        // TODO: Set the `clientId` and `redirectUri` arguments to the values you entered in the Apple Developer portal during the setup
                        clientId:
                            'de.lunaone.flutter.signinwithappleexample.service',
    
                        redirectUri:
                            // For web your redirect URI needs to be the host of the "current page",
                            // while for Android you will be using the API server that redirects back into your app via a deep link
                            kIsWeb
                                ? Uri.parse('https://${window.location.host}/')
                                : Uri.parse(
                                    'https://flutter-sign-in-with-apple-example.glitch.me/callbacks/sign_in_with_apple',
                                  ),
                      ),
                      // TODO: Remove these if you have no need for them
                      nonce: 'example-nonce',
                      state: 'example-state',
                    );
    
                    // ignore: avoid_print
                    print(credential);
    
                    // This is the endpoint that will convert an authorization code obtained
                    // via Sign in with Apple into a session in your system
                    final signInWithAppleEndpoint = Uri(
                      scheme: 'https',
                      host: 'flutter-sign-in-with-apple-example.glitch.me',
                      path: '/sign_in_with_apple',
                      queryParameters: <String, String>{
                        'code': credential.authorizationCode,
                        if (credential.givenName != null)
                          'firstName': credential.givenName!,
                        if (credential.familyName != null)
                          'lastName': credential.familyName!,
                        'useBundleId':
                            !kIsWeb && (Platform.isIOS || Platform.isMacOS)
                                ? 'true'
                                : 'false',
                        if (credential.state != null) 'state': credential.state!,
                      },
                    );
    
                    final session = await http.Client().post(
                      signInWithAppleEndpoint,
                    );
    
                    // If we got this far, a session based on the Apple ID credential has been created in your system,
                    // and you can now set this as the app's session
                    // ignore: avoid_print
                    print(session);
                  },
                ),
              ),
            ),
          ),
        );
      }
    }
    
    image.png

    4.shared_preferences
    为简单数据包装特定平台的持久存储(iOS和macOS上的NSUserDefaults, Android上的SharedPreferences,等等)。数据可以异步持久化到磁盘,并且不能保证写入在返回后会持久化到磁盘,所以这个插件不能用于存储关键数据。 支持的数据类型有int、double、bool、String和List<String>。

    相关文章

      网友评论

          本文标题:Flutter三方库介绍和梳理

          本文链接:https://www.haomeiwen.com/subject/hovyrrtx.html