base 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 36

logo

flutter_base #

实现一套代码,2种模式,ios使用Cupertino风格组件,andriod、fuchsia使用Material风格组件 #

使用dev分支 #

English #

当前只针对Cupertino模式进行了测试,Material组件相对比较完善了,后期也会补上Material模式的测试。 #

基础类 #

  • BaseStatelessWidget

    继承于StatelessWidget,用于构建无状态组件

    子类必须实现 buildByCupertino、buildByMaterial 方法,分别用于构建2种模式

  • BaseStatefulWidget

    继承于StatefulWidget,用于构建状态组件

    子类的State类必须继承 BaseState 类并实现 buildByCupertino、buildByMaterial 方法,分别用于构建2种模式

  • BaseClass

    普通基础类,用于构建普通类

    子类必须实现 buildByCupertino、buildByMaterial 方法分别用于构建2种模式

  • basePlatform 参数

    当前构建的平台,默认为 defaultTargetPlatform

    使用 setPlatform(TargetPlatform targetPlatform) 方法修改平台

    推荐使用 BaseApp(targetPlatform: TargetPlatform...) 设置平台

    默认 TargetPlatform.iOS 使用 Cupertino 构建, TargetPlatform.androidTargetPlatform.fuchsia 使用 Material 构建

Features #

  • useCupertino, useMaterial 使用这2个方法可以判断当前使用的模式,进行差异化构建。

  • 每个基础组件都含有 Map<String, dynamic> cupertino, Map<String, dynamic> material 2个参数,用于组件模式差异化设置,2种模式有公共参数的,会优先取当前模式下的值,再取公共值,如:

    BaseIcon(
      // materil模式下先取material参数里的icon参数,取不到再取该值
      icon: Icons.info,
      cupertino: <String, dynamic>{
        // cupertino模式下先取该值,因为取得到,所以不会取外层的icon
        'icon': CupertinoIcons.info,
      }
    );
    

    cupertino模式下使用的是CupertinoIcons.info,material模式下使用的是Icons.info

    features_demo
  • 可以使用 forceUseMaterial, forceUseCupertino 进行强制切换模式构建,使用 disabled 禁止构建(会用 Container() 代替)

    cupertino: {
      // 可使该组件强制使用Material构建
      forceUseMaterial: true,
      // 可使该组件不进行构建,但会使用Container()代替
      disabled: true,
    }
    material: {
      // 可使该组件强制使用Cupertino构建
      forceUseCupertino: true,
      // 可使该组件不进行构建,但会使用Container()代替
      disabled: true,
    }
    
  • 特别说明,非常重要 #

    forceUseMaterial, forceUseCupertino 参数未经严格测试,请慎用!慎用!慎用!

    很多material组件是需要有Material祖先的,在Cupertino模式下设置forceUseMaterial: true时,会默认套上一层Material,且默认会去除水波纹效果,此时BaseApp上的cupertinoTheme参数是不生效的,可能会出现样式混乱等不可预知的bug,所以请慎用,后续可能会删除这2个参数

如果要切换模式,强烈建议直接设置BaseApp's targetPlatform参数 #

组件列表 #

组件Material组件Cupertino组件
BaseActionSheetcustom BottomSheetCupertinoActionSheet
BaseActionSheetActionFlatButtonCupertinoActionSheetAction
BaseAppMaterialAppCupertinoApp
BaseAppBarAppBarCupertinoNavigationBar
BaseButtonMaterialButton
FlatButton, FlatButton.icon
OutlineButton, OutlineButton.icon
RaisedButton, RaiseButton.icon
CupertinoButton, CupertinoButton.filled
BaseIconButtonIconButtonCupertinoButton
BaseAlertDialogAlertDialogCupertinoAlertDialog
BaseDialogActionFlatButtonCupertinoDialogAction
BaseIconIconIcon
BaseIndicatorCircularProgressIndicatorCupertinoActivityIndicator
BaseRefreshRefreshIndicatorCustomScrollView + CupertinoSliverRefreshControl
BaseScaffoldScaffoldCupertinoPageScaffold
BaseTabScaffoldScaffoldCupertinoTabScaffold
BaseScrollBarScrollBarCupertinoScrollBar
BaseSectioncustom Containercustom Container
BaseTileListTilecustom InkWell without splash
BaseSliderSliderCupertinoSlider
BaseSwitchSwitchCupertinoSwitch
BaseBarItemBottomNavigationBarItemBottomNavigationBarItem
BaseTabBarBottomNavigationBarCupertinoTabBar
BaseTextFieldTextFieldCupertinoTextField
BaseDrawer//

简单示例 #

0.3.1 - 2019.12.30 #

  • fix example's bugs

0.3.0 - 2019.12.29 #

  • Release v0.3.0
  • incompatible with older versions
  • rename package utils to tools
  • remove base_theme's tileBackgroundColor
  • update flutter version to 1.13.5
  • fix bugs
  • the example instead provider to flutter_redux
  • the example support iOS13 dart mode

0.2.1 - 2019.11.14 #

  • Release v0.2.1
  • update flutter version to 1.11.0

0.2.0 - 2019.07.16 #

  • Release v0.2.0
  • add BaseTheme
  • add general components, like custom drawer
  • modify the CupertinoPageRoute, let BaseRoute's CupertinoPageRoute can custom the backGestureWidth
  • fix code format
  • update document
  • update flutter version to 1.8.1

0.1.9 - 2019.05.02 #

  • Release v0.1.9
  • modify CupertinoTabBar, CupertinoTabScaffold, BottomNavigationBar, BottomNavigationBarItem
  • BottomNavigationBarItem's icon can be null.

0.1.8 - 2019.04.28 #

  • Release v0.1.8
  • add BaseTextField
  • add example's screenshot

0.1.7 - 2019.04.26 #

  • Release v0.1.7
  • add BaseActionSheet
  • fix BaseTabScaffold

0.1.6 - 2019.04.25 #

  • Release v0.1.6
  • change cupertino,material to Map<String, dynamic>

0.1.5 - 2019.04.24 #

  • Release v0.1.5

0.1.4 - 2019.04.24 #

  • Release v0.1.4

0.1.3 - 2019.04.23 #

  • Release v0.1.3
  • add routes demo
  • add refresh demo
  • improve the document
  • change the default README.md to Chinese

0.1.2 - 2019.04.23 #

  • Release v0.1.2
  • fix BaseAppBar's bug
  • add alert dialog demo
  • add button demo

0.1.1 - 2019.04.21 #

  • Release v0.1.1
  • add analysis_options.yaml

0.1.0 - 2019.04.20 #

  • Release v0.1.0

0.0.3 - 2019.04.19 #

  • Release v0.0.3

0.0.2 - 2019.04.19 #

  • Release v0.0.2

0.0.1 - 2019.04.16 #

  • Release v0.0.1

example/lib/main.dart

import 'dart:io' show Platform;

import 'package:example/app.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'
    show debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show DeviceOrientation, SystemChrome;
import 'package:provider/provider.dart';

import 'provider/app_provider.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  _setTargetPlatformForDesktop();
  SystemChrome.setPreferredOrientations(<DeviceOrientation>[
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]).then((_) {
    runApp(
      ChangeNotifierProvider<AppProvider>.value(
        value: AppProvider(
          brightness: WidgetsBinding.instance.window.platformBrightness,
        ),
        child: App(),
      ),
    );
  });
}

/// 适配桌面客户端,mac用ios,windows,linux用android
void _setTargetPlatformForDesktop() {
  TargetPlatform targetPlatform;
  if (Platform.isMacOS) {
    targetPlatform = TargetPlatform.iOS;
  } else if (Platform.isLinux || Platform.isWindows) {
    targetPlatform = TargetPlatform.android;
  }
  if (targetPlatform != null) {
    debugDefaultTargetPlatformOverride = targetPlatform;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  base: ^0.3.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:base/base.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
36
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Fix lib/text_field/base_text_field.dart. (-82.20 points)

Analysis of lib/text_field/base_text_field.dart failed with 6 errors, including:

line 164 col 9: Undefined class 'SmartDashesType'.

line 169 col 9: Undefined class 'SmartQuotesType'.

line 345 col 7: The named parameter 'smartDashesType' isn't defined.

line 346 col 7: The named parameter 'smartQuotesType' isn't defined.

line 425 col 7: The named parameter 'smartDashesType' isn't defined.

Fix lib/app/base_app.dart. (-68.36 points)

Analysis of lib/app/base_app.dart failed with 4 errors:

line 291 col 9: The named parameter 'shortcuts' isn't defined.

line 292 col 9: The named parameter 'actions' isn't defined.

line 371 col 9: The named parameter 'shortcuts' isn't defined.

line 372 col 9: The named parameter 'actions' isn't defined.

Fix lib/button/base_button.dart. (-68.36 points)

Analysis of lib/button/base_button.dart failed with 4 errors:

line 224 col 9: Undefined class 'VisualDensity'.

line 327 col 9: The named parameter 'visualDensity' isn't defined.

line 353 col 9: The named parameter 'visualDensity' isn't defined.

line 409 col 7: The named parameter 'visualDensity' isn't defined.

Fix additional 22 files with analysis or formatting issues. (-188.32 points)

Additional issues in the following files:

  • lib/flutter/material/app_bar.dart (4 errors)
  • lib/button/base_icon_button.dart (2 errors)
  • lib/dialog/base_dialog_action.dart (2 errors)
  • lib/switch/base_switch.dart (1 error)
  • lib/components/base_expansion.dart (5 hints)
  • lib/route/base_route.dart (4 hints)
  • lib/action_sheet/base_action_sheet.dart (3 hints)
  • lib/dialog/base_alert_dialog.dart (2 hints)
  • lib/dialog/base_general_dialog.dart (1 hint)
  • lib/base.dart (Run flutter format to format lib/base.dart.)
  • lib/components/base_components.dart (Run flutter format to format lib/components/base_components.dart.)
  • lib/components/base_drawer.dart (Run flutter format to format lib/components/base_drawer.dart.)
  • lib/flutter/cupertino/bottom_tab_bar.dart (Run flutter format to format lib/flutter/cupertino/bottom_tab_bar.dart.)
  • lib/flutter/cupertino/nav_bar.dart (Run flutter format to format lib/flutter/cupertino/nav_bar.dart.)
  • lib/flutter/cupertino/route.dart (Run flutter format to format lib/flutter/cupertino/route.dart.)
  • lib/flutter/cupertino/tab_scaffold.dart (Run flutter format to format lib/flutter/cupertino/tab_scaffold.dart.)
  • lib/flutter/material/bottom_navigation_bar.dart (Run flutter format to format lib/flutter/material/bottom_navigation_bar.dart.)
  • lib/flutter/widgets/bottom_navigation_bar_item.dart (Run flutter format to format lib/flutter/widgets/bottom_navigation_bar_item.dart.)
  • lib/refresh/base_refresh.dart (Run flutter format to format lib/refresh/base_refresh.dart.)
  • lib/scaffold/base_tab_scaffold.dart (Run flutter format to format lib/scaffold/base_tab_scaffold.dart.)
  • lib/tabbar/base_tab_bar.dart (Run flutter format to format lib/tabbar/base_tab_bar.dart.)
  • lib/theme/base_theme.dart (Run flutter format to format lib/theme/base_theme.dart.)

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.8.0+1