Skip to content

Commit

Permalink
Merge branch 'develop' into dev/yisheng
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan730 committed Jan 13, 2019
2 parents b43cd20 + 8f200fc commit a3036f2
Show file tree
Hide file tree
Showing 33 changed files with 416 additions and 74 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Flutter 菜鸟手册
## Flutter Go

> 帮助开发者快速上手 Flutter **内部测试中,1.0 正式版将于 2月 20日 发布。**
Expand All @@ -25,13 +25,13 @@ flutter优点主要包括:
- 灵活的界面设计以及控件组合
- 借助可以移植的GPU加速的渲染引擎以及高性能ARM代码运行时已达到高质量的用户体验

#### 菜鸟手册的由来
#### Flutter Go 的由来

- Flutter学习资料太少,对于英文不好的同学相对来说比较困难
- 官网文档示例不够健全,不够直观
- 各个 widget 的用法各异,属性纷繁,要运行一个 widget 的 demo 往往要到处翻阅各种资料

#### 菜鸟手册的优势
#### Flutter Go 的优势

- 详解常用widget多达 **130+**
- 配套 Demo 详解 widget 常规用法
Expand Down
2 changes: 1 addition & 1 deletion android/app/bin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_rookie_book"
android:label="flutter_go"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
Expand Down
Binary file modified assets/app.db
Binary file not shown.
2 changes: 1 addition & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_rookie_book</string>
<string>flutter_go</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down
63 changes: 54 additions & 9 deletions lib/common/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,81 @@ import 'dart:typed_data';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:flutter/services.dart' show rootBundle;
//const createSql = {
// 'cat': """
// CREATE TABLE "cat" (
// `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
// `name` TEXT NOT NULL UNIQUE,
// `depth` INTEGER NOT NULL DEFAULT 1,
// `parentId` INTEGER NOT NULL,
// `desc` TEXT
// );
// """,
// 'collectio': """
// CREATE TABLE collection (id INTEGER PRIMARY KEY NOT NULL UNIQUE, name TEXT NOT NULL, router TEXT);
// """,
// 'widget': """
// CREATE TABLE widget (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, name TEXT NOT NULL, cnName TEXT NOT NULL, image TEXT NOT NULL, doc TEXT, demo TEXT, catId INTEGER NOT NULL REFERENCES cat (id), owner TEXT);
// """;
//};

class Provider {
static Database db;

// 获取数据库中所有的表
Future<List> getTables() async {
if (db == null) {
return Future.value([]);
}
List tables = await db.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
List<String> targetList = [];
tables.forEach((item) {
targetList.add(item['name']);
});
return targetList;
}

// 检查数据库中, 表是否完整, 在部份android中, 会出现表丢失的情况
Future checkTableIsRight() async {
List<String> expectTables = ['cat', 'widget', 'collection'];

List<String> tables = await getTables();

for(int i = 0; i < expectTables.length; i++) {
if (!tables.contains(expectTables[i])) {
print("table lost in app");
return false;
}
}
return true;

}

//初始化数据库
// isCreate 用永远 copy 一个新的数据库

Future init(bool isCreate) async {
//Get a location using getDatabasesPath
String databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'flutter.db');
List<Map> tables;

try {
db = await openDatabase(path);
tables = await db
.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
print('${tables.length} 7891');
} catch (e) {
print("Error $e");
}
bool tableIsRight = await this.checkTableIsRight();

if (tables.length < 3) {
// Delete the database
await deleteDatabase(path);
if (!tableIsRight) {
// 关闭上面打开的db,否则无法执行open
db.close();
// Delete the database
await deleteDatabase(path);
ByteData data = await rootBundle.load(join("assets", "app.db"));
List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await new File(path).writeAsBytes(bytes);

db = await openDatabase(path, version: 2,
db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
print('db created version is $version');
}, onOpen: (Database db) async {
Expand All @@ -44,4 +88,5 @@ class Provider {
print("Opening existing database");
}
}

}
4 changes: 1 addition & 3 deletions lib/components/comp_list.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_rookie_book/views/detail.dart';


import 'package:flutter_go/views/Detail.dart';

class CompList extends StatefulWidget {
@override
Expand Down
5 changes: 1 addition & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import 'routers/application.dart';
import 'common/provider.dart';
import 'model/widget.dart';
import './widgets/index.dart';
import 'package:flutter_rookie_book/components/search_input.dart';



import 'package:flutter_go/components/search_input.dart';
const int ThemeColor = 0xFFC91B3A;

class MyApp extends StatelessWidget {
Expand Down
12 changes: 7 additions & 5 deletions lib/views/first_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_rookie_book/common/list_view_item.dart';
import 'package:flutter_rookie_book/components/list_refresh.dart' as listComp;
import 'package:flutter_rookie_book/components/pagination.dart';
import 'package:flutter_rookie_book/components/first_page_item.dart';
import 'package:flutter_rookie_book/components/disclaimer_msg.dart';

import 'package:flutter_go/common/list_view_item.dart';
import 'package:flutter_go/components/list_refresh.dart' as listComp;
import 'package:flutter_go/components/pagination.dart';
import 'package:flutter_go/components/first_page_item.dart';
import 'package:flutter_go/components/disclaimer_msg.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../common/net_utils.dart';

GlobalKey<DisclaimerMsgState> key;
Expand Down
2 changes: 1 addition & 1 deletion lib/views/widget_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @Last Modified time: 2019-01-11 14:40:09
*/
import 'package:flutter/material.dart';
import 'package:flutter_rookie_book/components/cate_card.dart';
import 'package:flutter_go/components/cate_card.dart';
import '../model/cat.dart';

class WidgetPage extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/components/Bar/AppBar/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import './demo.dart' as AppBarDemo;
const String _Text0 =
"""### **简介**
> AppBar “应用栏”
- 应用栏由工具栏和可能的其他 widget 组成,例如 TabBar和FlexibleSpaceBar;
- 应用栏由工具栏组成,或者是工具栏和其他 widget 组合形成,例如 TabBar和FlexibleSpaceBar;
- 应用栏通常用于 Scaffold.appBar 属性,该属性将应用栏放置在屏幕顶部的固定高度小部件中;
- 对于可滚动的应用栏,请参阅SliverAppBar,它将AppBar嵌入 sliver 中以便在CustomScrollView中使用;
""";
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/components/Card/Card/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import './demo.dart' as CardDemo;
const String _Text0 =
"""### **简介**
> Card “卡片”
- 卡片是用于表示一些相关信息的一张材料,例如相册,地理位置,用餐,联系方式等
- 卡片用于表示一些相关信息,例如相册,地理位置,用餐,联系方式等
""";


Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/components/Chip/ChipThemeData/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const String content0 = '''
const String content1 = '''
### **基本用法**
- 创建ChipThemeData最简单的方法是使用copyWith您从得到一个ChipTheme.of,
或创建一个全新的一个具有 ChipThemeData..fromDefaults。。
或创建一个全新的一个具有 ChipThemeData..fromDefaults
''';

class Demo extends StatefulWidget {
Expand Down
7 changes: 4 additions & 3 deletions lib/widgets/components/Dialog/AboutDialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import 'demo.dart';
const String _Text0 = """
### **简介**
> AboutDialog 通常用于传递企业或者app的官方信息
- 这个对话框包含应用程序的图标,名称,版本号,版权和应用程序使用到的软件许可证的按钮
### **基本用法**
> 通常作为子窗口小部件传递给showDialog,后者显示对话框。
> 要显示的AboutDialog,使用showAboutDialog。
- 如果应用程序具有Drawer,则AboutListTile可以使显示AboutDialog的过程更简单。
- AboutDialog通过showAboutDialog 显示按钮调用 showLicensePage。
""";

Expand Down
14 changes: 5 additions & 9 deletions lib/widgets/components/Dialog/AlertDialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ import 'demo.dart';

const String _Text0 = """
### **简介**
> AlertDialog 向用户传递信息的弹出层。
> AlertDialog 向用户传递信息的弹出层。警报对话框
- 一般使用在通知用户需要确认的情况,具有可选标题和可选的操纵列表。标题显示在上方,操纵内容显示在内容区域,即下方
### **基本用法**
> 通常作为子窗口小部件传递给showDialog,后者显示对话框。
当**AlertDialog**的的元素过多过长时, 请优先考虑**SingleChildScrollView** 用来避免内容溢出
- 当**AlertDialog**的的元素过多过长时, 请优先考虑**SingleChildScrollView** 用来避免内容溢出
- 需要注意的是,由于AlertDialog 通常使用child的大小来调整自身大小,所以使用一些widget(如ListView,GridView和CustomScrollView)将无法正常工作
- 当需要给用户提供多个选项的供选择时,请使用SimpleDialog
""";


Expand Down
49 changes: 39 additions & 10 deletions lib/widgets/components/Dialog/Dialog/demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ class _Demo extends State<DialogDemo> {
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return Dialog(
child: Text("我是一个Dialog"),
child: Container(
height: 100,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text('我是一个dialog'),
RaisedButton(
child: Text('取消'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
)
);
},
);
Expand Down Expand Up @@ -63,15 +77,30 @@ class _DialogMoreDemo extends State<DialogMoreDemo> {
return StatefulBuilder(
builder: (context, state) {
return Dialog(
child: RaisedButton(
onPressed: () {
print("print $value");
state(() {
value += 1;
});
},
child: Text("我是一个Dialog, 点我更新value: $value"),
)
child: Container(
height: 150,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text('我是一个dialog'),
RaisedButton(
onPressed: () {
state(() {
value += 1;
});
},
child: Text("我是一个Dialog, 点我更新value: $value"),
),
RaisedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("取消"),
)
],
),
),

);
}
);
Expand Down
7 changes: 2 additions & 5 deletions lib/widgets/components/Dialog/Dialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ import 'demo.dart';

const String _Text0 = """
### **简介**
> AlertDialog 向用户传递信息的弹出层。
这个组件没有任何可操作的选项. 相比使用这个组件, 通常我们更喜欢使用 **AlertDialog**或者**SimpleDialog**
> Dialog 向用户传递信息的弹出层。
-这个组件没有任何可操作的选项. 相比使用这个组件, 通常我们更喜欢使用 **AlertDialog**或者**SimpleDialog**
### **基本用法**
> 通常作为子窗口小部件传递给showDialog,后者显示对话框。
""";

const String _Text1 = """
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/components/Dialog/SimpleDialog/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import 'demo.dart';
const String _Text0 = """
### **简介**
> SimpleDialog 是一个用于向用户传递确定信息并提供选项的弹出层
- SimpleDialog 可为用户提供多个选项选择。有一个可选的标题,显示在选项上方
### **基本用法**
> 通常作为子窗口小部件传递给showDialog,后者显示对话框。
- 选择通常使用SimpleDialogOption表示
- 对于通知用户情况的对话框,请考虑使用 AlertDialog。
""";

Expand Down
Loading

0 comments on commit a3036f2

Please sign in to comment.