Skip to content

Commit

Permalink
Merge pull request #42 from alibaba/develop
Browse files Browse the repository at this point in the history
解决issue中反馈来的问题, 并且完善一部份功能
  • Loading branch information
hanxu317317 authored Jan 14, 2019
2 parents 149c58a + 9e22325 commit 858055f
Show file tree
Hide file tree
Showing 88 changed files with 1,294 additions and 489 deletions.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/common/iconNames.dart → lib/common/icon_names.dart

Large diffs are not rendered by default.

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");
}
}

}
29 changes: 29 additions & 0 deletions lib/common/style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';

//颜色配置
class AppColor{
static const int white = 0xFFFFFFFF;
static const int mainTextColor = 0xFF121917;
static const int subTextColor = 0xff959595;
}

//文本设置
class AppText{
static const middleSize = 16.0;

static const middleText = TextStyle(
color: Color(AppColor.mainTextColor),
fontSize: middleSize,
);

static const middleSubText = TextStyle(
color: Color(AppColor.subTextColor),
fontSize: middleSize,
);
}
class WidgetDemoColor {
static const int fontColor = 0xFF607173;
static const int iconColor = 0xFF607173;
static const int borderColor = 0xFFEFEFEF;

}
7 changes: 6 additions & 1 deletion lib/common/widget_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ class WidgetDemo extends StatefulWidget {
final String docUrl;
final String title;
final String codeUrl;
final Widget bottomNaviBar;

WidgetDemo(
{Key key,
@required this.title,
@required this.contentList,
@required this.codeUrl,
@required this.docUrl})
@required this.docUrl,
this.bottomNaviBar
})
: super(key: key);

_WidgetDemoState createState() => _WidgetDemoState();
Expand Down Expand Up @@ -207,6 +210,8 @@ class _WidgetDemoState extends State<WidgetDemo> {
],
),
),
bottomNavigationBar: (widget.bottomNaviBar is Widget) ? widget
.bottomNaviBar : null
);
}
}
12 changes: 9 additions & 3 deletions lib/common/widget_name_to_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ class WidgetName2Icon {
"YearPicker":Icons.event_busy,
"ShowdatePicker":Icons.event,
"MaterialPageRoute":Icons.album,
"MaterialAccentColor":Icons.brush,


"MaterialAccentColor":Icons.brush,
"SnackBarAction":Icons.assessment,
"TabBar":Icons.burst_mode,
"AlertDialog":Icons.sms_failed,
"AboutDialog":Icons.sms,
"SimpleDialog":Icons.message,
"ScaffoldState":Icons.local_bar,
"GridTile":Icons.apps,
"MergeableMaterialItem":Icons.view_list
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import '../../model/cat.dart';
import '../../common/widget_name_to_icon.dart';
import '../../components/widget_item_container.dart';
import '../model/cat.dart';
import '../common/widget_name_to_icon.dart';
import '../components/widget_item_container.dart';

class CateCard extends StatefulWidget {
final Cat category;
Expand Down
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
Loading

0 comments on commit 858055f

Please sign in to comment.