diff --git a/README.md b/README.md index 7c74055..ff48048 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # ansu_ui 安速物流移动组件 ## Getting Started + +## 贡献 + +### 组件命名 + +* 命名规则 `as_***`,例如 `as_button` diff --git a/example/lib/example_scaffold.dart b/example/lib/example_scaffold.dart new file mode 100644 index 0000000..73145ea --- /dev/null +++ b/example/lib/example_scaffold.dart @@ -0,0 +1,18 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:flutter/material.dart'; + +class ExampleScaffold extends StatefulWidget { + ExampleScaffold({Key key}) : super(key: key); + + @override + _ExampleScaffoldState createState() => _ExampleScaffoldState(); +} + +class _ExampleScaffoldState extends State { + @override + Widget build(BuildContext context) { + return ASScaffold( + title: '标题', + ); + } +} diff --git a/example/lib/main.dart b/example/lib/main.dart index 25e0508..e6cab32 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,9 @@ import 'package:ansu_ui/ansu_ui.dart'; import 'package:ansu_ui/buttons/as_button.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import 'example_scaffold.dart'; void main() { runApp(MyApp()); @@ -9,44 +12,24 @@ void main() { class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - ScreenUtil.init(context, - designSize: Size(750, 1334), allowFontScaling: false); - return MaterialApp( + return GetMaterialApp( title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. - primarySwatch: Colors.blue, - // This makes the visual density adapt to the platform that you run - // the app on. For desktop platforms, the controls will be smaller and - // closer together (more dense) than on mobile platforms. - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - home: MyHomePage(title: 'Flutter Demo Home Page'), + home: _ScreenAdapter(), ); } } -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". +class _ScreenAdapter extends StatelessWidget { + @override + Widget build(BuildContext context) { + ScreenUtil.init(context, + designSize: Size(375, 812), allowFontScaling: false); + return MyHomePage(); + } +} - final String title; +class MyHomePage extends StatefulWidget { + MyHomePage({Key key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); @@ -57,12 +40,17 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(widget.title), + title: Text('title'), ), body: ListView( children: [ ASButton.gray('删除订单', (){}), SizedBox(height: 12.w), + TextButton( + onPressed: () { + Get.to(ExampleScaffold()); + }, + child: Text('SCAFFOLD')), ], ), ); diff --git a/example/pubspec.lock b/example/pubspec.lock index 3debf10..d1a090b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -81,6 +81,13 @@ packages: description: flutter source: sdk version: "0.0.0" + get: + dependency: "direct main" + description: + name: get + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.17.1" matcher: dependency: transitive description: @@ -164,5 +171,5 @@ packages: source: hosted version: "2.1.0-nullsafety.3" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.10.0 <2.11.0" flutter: ">=1.17.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a4cfe97..4366aab 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -30,6 +30,7 @@ dependencies: cupertino_icons: ^1.0.0 ansu_ui: path: ../ + get: dev_dependencies: flutter_test: diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index eaa905d..07c84a5 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -1,4 +1,8 @@ library ansu_ui; export 'buttons/as_button.dart'; +export 'scaffold/as_scaffold.dart'; +export 'styles/as_colors.dart'; + +//`BOTTOM` is external lib export 'package:flutter_screenutil/flutter_screenutil.dart'; diff --git a/lib/buttons/as_back_button.dart b/lib/buttons/as_back_button.dart new file mode 100644 index 0000000..0746457 --- /dev/null +++ b/lib/buttons/as_back_button.dart @@ -0,0 +1,26 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class ASBackButton extends StatelessWidget { + final Color color; + const ASBackButton({Key key, this.color = kDarkColor}) : super(key: key); + + const ASBackButton.white({Key key}) + : color = kForegroundColor, + super(key: key); + + @override + Widget build(BuildContext context) { + return Navigator.canPop(context) + ? IconButton( + icon: Icon( + CupertinoIcons.chevron_back, + size: 24, + color: color, + ), + onPressed: () => Navigator.pop(context), + ) + : SizedBox(); + } +} diff --git a/lib/scaffold/as_scaffold.dart b/lib/scaffold/as_scaffold.dart new file mode 100644 index 0000000..96610f8 --- /dev/null +++ b/lib/scaffold/as_scaffold.dart @@ -0,0 +1,55 @@ +import 'package:ansu_ui/buttons/as_back_button.dart'; +import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +///ASScaffold +/// +///made with Scaffold from `Material` +/// +///`title`,`body` +/// +///`leading` +class ASScaffold extends StatefulWidget { + ///标题,可为`String`或`Text` + final dynamic title; + + /// `Scaffold` body + final Widget body; + + /// `Scaffold` leading + final Widget leading; + ASScaffold({ + Key key, + @required this.title, + this.leading, + this.body, + }) : super(key: key); + + @override + _ASScaffoldState createState() => _ASScaffoldState(); +} + +class _ASScaffoldState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: kBackgroundColor, + appBar: AppBar( + backgroundColor: kForegroundColor, + elevation: 0, + leading: ASBackButton(), + centerTitle: true, + title: DefaultTextStyle( + style: TextStyle( + color: kTextColor, + fontSize: 18.sp, + fontWeight: FontWeight.bold, + ), + child: widget.title is String ? Text(widget.title) : widget.title, + ), + ), + body: widget.body, + ); + } +} diff --git a/lib/styles/as_colors.dart b/lib/styles/as_colors.dart new file mode 100644 index 0000000..a553f9c --- /dev/null +++ b/lib/styles/as_colors.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; + +///主要暗色 +const Color kDarkColor = Color(0xFF333333); + +///文本默认颜色 +const Color kTextColor = kDarkColor; + +///主题色 +const Color kPrimaryColor = Color(0xFFF6B72D); + +///前景色 +const Color kForegroundColor = Color(0xFFFFFFFF); + +///背景色 +const Color kBackgroundColor = Color(0xFFF6F6F6);