Skip to content

Commit 858055f

Browse files
authored
Merge pull request #42 from alibaba/develop
解决issue中反馈来的问题, 并且完善一部份功能
2 parents 149c58a + 9e22325 commit 858055f

File tree

88 files changed

+1294
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1294
-489
lines changed

android/app/bin/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
FlutterApplication and put your custom class here. -->
1515
<application
1616
android:name="io.flutter.app.FlutterApplication"
17-
android:label="flutter_rookie_book"
17+
android:label="flutter_go"
1818
android:icon="@mipmap/ic_launcher">
1919
<activity
2020
android:name=".MainActivity"

assets/app.db

0 Bytes
Binary file not shown.

ios/Runner/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>
16-
<string>flutter_rookie_book</string>
16+
<string>flutter_go</string>
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
File renamed without changes.

lib/common/iconNames.dart lib/common/icon_names.dart

+1-1
Large diffs are not rendered by default.

lib/common/provider.dart

+54-9
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,81 @@ import 'dart:typed_data';
44
import 'package:path/path.dart';
55
import 'package:sqflite/sqflite.dart';
66
import 'package:flutter/services.dart' show rootBundle;
7+
//const createSql = {
8+
// 'cat': """
9+
// CREATE TABLE "cat" (
10+
// `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
11+
// `name` TEXT NOT NULL UNIQUE,
12+
// `depth` INTEGER NOT NULL DEFAULT 1,
13+
// `parentId` INTEGER NOT NULL,
14+
// `desc` TEXT
15+
// );
16+
// """,
17+
// 'collectio': """
18+
// CREATE TABLE collection (id INTEGER PRIMARY KEY NOT NULL UNIQUE, name TEXT NOT NULL, router TEXT);
19+
// """,
20+
// 'widget': """
21+
// 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);
22+
// """;
23+
//};
724

825
class Provider {
926
static Database db;
1027

28+
// 获取数据库中所有的表
29+
Future<List> getTables() async {
30+
if (db == null) {
31+
return Future.value([]);
32+
}
33+
List tables = await db.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
34+
List<String> targetList = [];
35+
tables.forEach((item) {
36+
targetList.add(item['name']);
37+
});
38+
return targetList;
39+
}
40+
41+
// 检查数据库中, 表是否完整, 在部份android中, 会出现表丢失的情况
42+
Future checkTableIsRight() async {
43+
List<String> expectTables = ['cat', 'widget', 'collection'];
44+
45+
List<String> tables = await getTables();
46+
47+
for(int i = 0; i < expectTables.length; i++) {
48+
if (!tables.contains(expectTables[i])) {
49+
print("table lost in app");
50+
return false;
51+
}
52+
}
53+
return true;
54+
55+
}
56+
1157
//初始化数据库
12-
// isCreate 用永远 copy 一个新的数据库
58+
1359
Future init(bool isCreate) async {
1460
//Get a location using getDatabasesPath
1561
String databasesPath = await getDatabasesPath();
1662
String path = join(databasesPath, 'flutter.db');
17-
List<Map> tables;
63+
1864
try {
1965
db = await openDatabase(path);
20-
tables = await db
21-
.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
22-
print('${tables.length} 7891');
2366
} catch (e) {
2467
print("Error $e");
2568
}
69+
bool tableIsRight = await this.checkTableIsRight();
2670

27-
if (tables.length < 3) {
28-
// Delete the database
29-
await deleteDatabase(path);
71+
if (!tableIsRight) {
3072
// 关闭上面打开的db,否则无法执行open
3173
db.close();
74+
// Delete the database
75+
await deleteDatabase(path);
3276
ByteData data = await rootBundle.load(join("assets", "app.db"));
3377
List<int> bytes =
3478
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
3579
await new File(path).writeAsBytes(bytes);
3680

37-
db = await openDatabase(path, version: 2,
81+
db = await openDatabase(path, version: 1,
3882
onCreate: (Database db, int version) async {
3983
print('db created version is $version');
4084
}, onOpen: (Database db) async {
@@ -44,4 +88,5 @@ class Provider {
4488
print("Opening existing database");
4589
}
4690
}
91+
4792
}

lib/common/style.dart

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:flutter/material.dart';
2+
3+
//颜色配置
4+
class AppColor{
5+
static const int white = 0xFFFFFFFF;
6+
static const int mainTextColor = 0xFF121917;
7+
static const int subTextColor = 0xff959595;
8+
}
9+
10+
//文本设置
11+
class AppText{
12+
static const middleSize = 16.0;
13+
14+
static const middleText = TextStyle(
15+
color: Color(AppColor.mainTextColor),
16+
fontSize: middleSize,
17+
);
18+
19+
static const middleSubText = TextStyle(
20+
color: Color(AppColor.subTextColor),
21+
fontSize: middleSize,
22+
);
23+
}
24+
class WidgetDemoColor {
25+
static const int fontColor = 0xFF607173;
26+
static const int iconColor = 0xFF607173;
27+
static const int borderColor = 0xFFEFEFEF;
28+
29+
}

lib/common/widget_demo.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ class WidgetDemo extends StatefulWidget {
1818
final String docUrl;
1919
final String title;
2020
final String codeUrl;
21+
final Widget bottomNaviBar;
2122

2223
WidgetDemo(
2324
{Key key,
2425
@required this.title,
2526
@required this.contentList,
2627
@required this.codeUrl,
27-
@required this.docUrl})
28+
@required this.docUrl,
29+
this.bottomNaviBar
30+
})
2831
: super(key: key);
2932

3033
_WidgetDemoState createState() => _WidgetDemoState();
@@ -207,6 +210,8 @@ class _WidgetDemoState extends State<WidgetDemo> {
207210
],
208211
),
209212
),
213+
bottomNavigationBar: (widget.bottomNaviBar is Widget) ? widget
214+
.bottomNaviBar : null
210215
);
211216
}
212217
}

lib/common/widget_name_to_icon.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ class WidgetName2Icon {
137137
"YearPicker":Icons.event_busy,
138138
"ShowdatePicker":Icons.event,
139139
"MaterialPageRoute":Icons.album,
140-
"MaterialAccentColor":Icons.brush,
141-
142-
140+
"MaterialAccentColor":Icons.brush,
141+
"SnackBarAction":Icons.assessment,
142+
"TabBar":Icons.burst_mode,
143+
"AlertDialog":Icons.sms_failed,
144+
"AboutDialog":Icons.sms,
145+
"SimpleDialog":Icons.message,
146+
"ScaffoldState":Icons.local_bar,
147+
"GridTile":Icons.apps,
148+
"MergeableMaterialItem":Icons.view_list
143149
};
144150
}

lib/views/widgetPage/cate_card.dart lib/components/cate_card.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
2-
import '../../model/cat.dart';
3-
import '../../common/widget_name_to_icon.dart';
4-
import '../../components/widget_item_container.dart';
2+
import '../model/cat.dart';
3+
import '../common/widget_name_to_icon.dart';
4+
import '../components/widget_item_container.dart';
55

66
class CateCard extends StatefulWidget {
77
final Cat category;

lib/components/CompList.dart lib/components/comp_list.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_rookie_book/views/Detail.dart';
3-
4-
2+
import 'package:flutter_go/views/Detail.dart';
53

64
class CompList extends StatefulWidget {
75
@override

0 commit comments

Comments
 (0)