mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-07-04 07:18:11 +08:00
完成调试
This commit is contained in:
@ -9,5 +9,7 @@ class Api{
|
||||
static const String LOGOUT = BASE_URL+'logout';//退出登陆
|
||||
|
||||
static const String VERSION = BASE_URL+'getAppVersion';//检查版本
|
||||
|
||||
static const String GET_WIDGET_TREE = BASE_URL + 'getCateList';//获取widget列表树
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/cat.dart';
|
||||
import '../resources/widget_name_to_icon.dart';
|
||||
import '../components/widget_item_container.dart';
|
||||
import '../model/widget.dart';
|
||||
|
||||
class CateCard extends StatefulWidget {
|
||||
final Cat category;
|
||||
final CategoryComponent category;
|
||||
CateCard({@required this.category});
|
||||
@override
|
||||
_CateCardState createState() => _CateCardState();
|
||||
@ -13,28 +13,15 @@ class CateCard extends StatefulWidget {
|
||||
|
||||
class _CateCardState extends State<CateCard> {
|
||||
// 一级菜单目录下的二级Cat集合
|
||||
List<Cat> _firstChildList = new List();
|
||||
CatControlModel catControl = new CatControlModel();
|
||||
List<CommonItem> _firstChildList;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getFirstChildCategoriesByParentId();
|
||||
_firstChildList = widget.category.children;
|
||||
}
|
||||
|
||||
// 获取一层目录下的二级内容
|
||||
getFirstChildCategoriesByParentId() async {
|
||||
int parentId = widget.category.id;
|
||||
// 构建查询条件
|
||||
Cat childCateCondition = new Cat(parentId: parentId);
|
||||
|
||||
List<Cat> list = await catControl.getList(childCateCondition);
|
||||
if (list.isNotEmpty&&list.length>=1 && this.mounted) {
|
||||
setState(() {
|
||||
_firstChildList = list;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -43,7 +30,6 @@ class _CateCardState extends State<CateCard> {
|
||||
//首字母转为大写
|
||||
widget.category.name.substring(0, 1),
|
||||
widget.category.name.substring(0, 1).toUpperCase());
|
||||
|
||||
return Container(
|
||||
width: screenWidth,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
|
||||
@ -119,9 +105,8 @@ class _CateCardState extends State<CateCard> {
|
||||
),
|
||||
),
|
||||
child: WidgetItemContainer(
|
||||
categories: this._firstChildList,
|
||||
columnCount: 3,
|
||||
isWidgetPoint:false
|
||||
commonItems: this._firstChildList,
|
||||
columnCount: 3
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -8,11 +8,12 @@ import '../model/widget.dart';
|
||||
import '../widgets/index.dart';
|
||||
import '../components/widget_item_container.dart';
|
||||
|
||||
enum CateOrWigdet { Cat, WidgetDemo }
|
||||
|
||||
|
||||
class CategoryHome extends StatefulWidget {
|
||||
CategoryHome(this.name);
|
||||
final String name;
|
||||
CategoryHome(this.token);
|
||||
final String token;
|
||||
|
||||
|
||||
@override
|
||||
_CategoryHome createState() => new _CategoryHome();
|
||||
@ -21,12 +22,11 @@ class CategoryHome extends StatefulWidget {
|
||||
class _CategoryHome extends State<CategoryHome> {
|
||||
String title = '';
|
||||
// 显示列表 cat or widget;
|
||||
List<Cat> categories = [];
|
||||
List<WidgetPoint> widgetPoints = [];
|
||||
List<Cat> catHistory = new List();
|
||||
List<CommonItem> items = [];
|
||||
List<Object> widgetPoints = [];
|
||||
List<CommonItem> catHistory = new List();
|
||||
|
||||
|
||||
CatControlModel catControl = new CatControlModel();
|
||||
WidgetControlModel widgetControl = new WidgetControlModel();
|
||||
// 所有的可用demos;
|
||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
||||
|
||||
@ -34,80 +34,74 @@ class _CategoryHome extends State<CategoryHome> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 初始化加入顶级的name
|
||||
this.getCatByName(widget.name).then((Cat cat) {
|
||||
catHistory.add(cat);
|
||||
searchCatOrWigdet();
|
||||
print("这是新界面的id:>>> ${widget.token}");
|
||||
|
||||
CommonItem targetGroup = Application.widgetTree.find(widget.token) ?? [];
|
||||
print("targetGroup::: $targetGroup");
|
||||
|
||||
catHistory.add(
|
||||
targetGroup
|
||||
);
|
||||
this.setState(() {
|
||||
items = targetGroup.children;
|
||||
});
|
||||
searchCatOrWidget();
|
||||
}
|
||||
|
||||
Future<Cat> getCatByName(String name) async {
|
||||
return await catControl.getCatByName(name);
|
||||
}
|
||||
|
||||
|
||||
Future<bool> back() {
|
||||
if (catHistory.length == 1) {
|
||||
// if (catHistory.length == 1) {
|
||||
// return Future<bool>.value(true);
|
||||
// }
|
||||
// catHistory.removeLast();
|
||||
// searchCatOrWidget();
|
||||
return Future<bool>.value(true);
|
||||
}
|
||||
catHistory.removeLast();
|
||||
searchCatOrWigdet();
|
||||
return Future<bool>.value(false);
|
||||
}
|
||||
|
||||
void go(Cat cat) {
|
||||
void go(CommonItem cat) {
|
||||
catHistory.add(cat);
|
||||
searchCatOrWigdet();
|
||||
searchCatOrWidget();
|
||||
}
|
||||
|
||||
void searchCatOrWigdet() async {
|
||||
// 假设进入这个界面的parent一定存在
|
||||
Cat parentCat = catHistory.last;
|
||||
|
||||
|
||||
// 继续搜索显示下一级depth: depth + 1, parentId: parentCat.id
|
||||
List<Cat> _categories =
|
||||
await catControl.getList(new Cat(parentId: parentCat.id));
|
||||
List<WidgetPoint> _widgetPoints = new List();
|
||||
if (_categories.isEmpty) {
|
||||
_widgetPoints =
|
||||
await widgetControl.getList(new WidgetPoint(catId: parentCat.id));
|
||||
}
|
||||
void searchCatOrWidget() async {
|
||||
print("searchCatOrWidget>>>");
|
||||
CommonItem widgetTree = Application.widgetTree;
|
||||
// // 假设进入这个界面的parent一定存在
|
||||
CommonItem targetGroup = catHistory.last;
|
||||
//
|
||||
//
|
||||
// // 继续搜索显示下一级depth: depth + 1, parentId: parentCat.id
|
||||
// List<Cat> _categories =
|
||||
// await catControl.getList(new Cat(parentId: parentCat.id));
|
||||
// List<WidgetPoint> _widgetPoints = new List();
|
||||
// if (_categories.isEmpty) {
|
||||
// _widgetPoints =
|
||||
// await widgetControl.getList(new WidgetPoint(catId: parentCat.id));
|
||||
// }
|
||||
//
|
||||
print("targetGroup >>> $targetGroup");
|
||||
|
||||
this.setState(() {
|
||||
categories = _categories;
|
||||
title = parentCat.name;
|
||||
widgetPoints = _widgetPoints;
|
||||
title = targetGroup.name;
|
||||
// widgetPoints = targetGroup.children;
|
||||
});
|
||||
}
|
||||
|
||||
void onCatgoryTap(Cat cat) {
|
||||
void onCatgoryTap(CommonItem cat) {
|
||||
print("onCatgoryTap: ${cat}");
|
||||
go(cat);
|
||||
}
|
||||
|
||||
void onWidgetTap(WidgetPoint widgetPoint) {
|
||||
String targetName = widgetPoint.name;
|
||||
String targetRouter = '/category/error/404';
|
||||
widgetDemosList.forEach((item) {
|
||||
// print("targetRouter = item.routerName> ${[item.name,targetName]}");
|
||||
if (item.name == targetName) {
|
||||
targetRouter = item.routerName;
|
||||
}
|
||||
});
|
||||
Application.router.navigateTo(context, "$targetRouter");
|
||||
}
|
||||
|
||||
|
||||
Widget _buildContent() {
|
||||
WidgetItemContainer wiContaienr = WidgetItemContainer(
|
||||
columnCount: 3,
|
||||
categories: categories,
|
||||
isWidgetPoint:false
|
||||
commonItems: items
|
||||
);
|
||||
if (widgetPoints.length > 0) {
|
||||
wiContaienr = WidgetItemContainer(
|
||||
categories: widgetPoints,
|
||||
columnCount: 3,
|
||||
isWidgetPoint:true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(bottom: 10.0, top: 5.0),
|
||||
decoration: BoxDecoration(
|
||||
@ -122,14 +116,18 @@ class _CategoryHome extends State<CategoryHome> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
title: Text("$title"),
|
||||
),
|
||||
body: WillPopScope(
|
||||
|
||||
onWillPop: () {
|
||||
return back();
|
||||
},
|
||||
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
_buildContent(),
|
||||
|
@ -3,56 +3,60 @@ import 'package:fluro/fluro.dart';
|
||||
import './widget_item.dart';
|
||||
import '../routers/application.dart';
|
||||
import '../widgets/index.dart';
|
||||
import '../model/widget.dart';
|
||||
|
||||
class WidgetItemContainer extends StatelessWidget {
|
||||
final int columnCount; //一行几个
|
||||
final List<dynamic> categories;
|
||||
final bool isWidgetPoint;
|
||||
final List<CommonItem> commonItems;
|
||||
// final bool isWidgetPoint;
|
||||
|
||||
// 所有的可用demos;
|
||||
final List widgetDemosList = new WidgetDemoList().getDemos();
|
||||
|
||||
WidgetItemContainer(
|
||||
{Key key,
|
||||
@required this.categories,
|
||||
@required this.commonItems,
|
||||
@required this.columnCount,
|
||||
@required this.isWidgetPoint})
|
||||
// @required this.isWidgetPoint
|
||||
})
|
||||
: super(key: key);
|
||||
|
||||
List<Widget> _buildColumns(context) {
|
||||
List<Widget> _listWidget = [];
|
||||
List<Widget> _listRows = [];
|
||||
int addI;
|
||||
for (int i = 0, length = categories.length; i < length; i += columnCount) {
|
||||
for (int i = 0, length = commonItems.length; i < length; i += columnCount) {
|
||||
_listRows = [];
|
||||
for (int innerI = 0; innerI < columnCount; innerI++) {
|
||||
addI = innerI + i;
|
||||
if (addI < length) {
|
||||
dynamic item = categories[addI];
|
||||
CommonItem item = commonItems[addI];
|
||||
_listRows.add(
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: WidgetItem(
|
||||
title: item.name,
|
||||
onTap: () {
|
||||
if (isWidgetPoint) {
|
||||
String targetName = item.name;
|
||||
if (item.type == 'widget') {
|
||||
WidgetLeaf _item = item;
|
||||
String targetName = _item.name;
|
||||
String targetRouter = '/category/error/404';
|
||||
widgetDemosList.forEach((item) {
|
||||
if (item.name == targetName) {
|
||||
targetRouter = item.routerName;
|
||||
}
|
||||
});
|
||||
Application.router.navigateTo(context, "$targetRouter", transition: TransitionType.inFromRight);
|
||||
} else {
|
||||
Application.router
|
||||
.navigateTo(context, "/category/${item.name}", transition: TransitionType.inFromRight);
|
||||
print("targetRouter>>> $targetRouter");
|
||||
|
||||
return Application.router.navigateTo(context, targetRouter, transition: TransitionType.inFromRight);
|
||||
}
|
||||
Application.router
|
||||
.navigateTo(context, "/category/${item.token}", transition: TransitionType.inFromRight);
|
||||
},
|
||||
index: addI,
|
||||
totalCount: length,
|
||||
rowLength: columnCount,
|
||||
textSize: isWidgetPoint ? 'middle' : 'small',
|
||||
textSize: true ? 'middle' : 'small',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -15,6 +15,7 @@ import 'package:flutter_go/model/search_history.dart';
|
||||
import 'package:flutter_go/utils/analytics.dart' as Analytics;
|
||||
import 'package:flutter_go/views/login_page/login_page.dart';
|
||||
import 'package:flutter_go/utils/data_utils.dart';
|
||||
import 'package:flutter_go/model/widget.dart';
|
||||
|
||||
//import 'views/welcome_page/index.dart';
|
||||
|
||||
@ -25,7 +26,6 @@ var db;
|
||||
class MyApp extends StatefulWidget {
|
||||
MyApp() {
|
||||
final router = new Router();
|
||||
|
||||
Routes.configureRoutes(router);
|
||||
|
||||
Application.router = router;
|
||||
@ -66,6 +66,7 @@ class _MyAppState extends State<MyApp> {
|
||||
});
|
||||
print('身份信息验证失败:$onError');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
_UpdateURL() async {
|
||||
@ -98,8 +99,9 @@ class _MyAppState extends State<MyApp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// WidgetTree.getCommonItemByPath([15, 17], Application.widgetTree);
|
||||
return new MaterialApp(
|
||||
title: 'title',
|
||||
title: 'titles',
|
||||
theme: new ThemeData(
|
||||
primaryColor: Color(ThemeColor),
|
||||
backgroundColor: Color(0xFFEFEFEF),
|
||||
@ -127,6 +129,11 @@ void main() async {
|
||||
await provider.init(true);
|
||||
sp = await SpUtil.getInstance();
|
||||
new SearchHistoryList(sp);
|
||||
await DataUtils.getWidgetTreeList().then((List json) {
|
||||
print("树型结构返回数据: $json");
|
||||
Application.widgetTree = WidgetTree.buildWidgetTree(json);
|
||||
|
||||
});
|
||||
db = Provider.db;
|
||||
runApp(new MyApp());
|
||||
}
|
||||
|
@ -5,6 +5,13 @@ import "package:flutter/material.dart";
|
||||
|
||||
import 'package:flutter_go/utils/sql.dart';
|
||||
|
||||
enum treeNode {
|
||||
CategoryComponent,
|
||||
WidgetLeaf
|
||||
}
|
||||
|
||||
//typedef aaa
|
||||
|
||||
abstract class WidgetInterface {
|
||||
int get id;
|
||||
|
||||
@ -142,3 +149,182 @@ class WidgetControlModel {
|
||||
return widgets;
|
||||
}
|
||||
}
|
||||
// 抽象类
|
||||
abstract class CommonItem<T> {
|
||||
int id;
|
||||
String name;
|
||||
int parentId;
|
||||
String type;
|
||||
List<CommonItem> children;
|
||||
String token;
|
||||
|
||||
/// 父级节点, 存放整个CommonItem对象node = ! null
|
||||
///
|
||||
CommonItem parent;
|
||||
String toString() {
|
||||
return "CommonItem {name: $name, type: $type, parentId: $parentId, token: $token, children长度 ${children}";
|
||||
}
|
||||
|
||||
T getChild(String token);
|
||||
T addChildren(Object item);
|
||||
// 从children树中. 查找任意子节点
|
||||
T find(String token, [CommonItem node]);
|
||||
}
|
||||
|
||||
// tree的group树干
|
||||
class CategoryComponent extends CommonItem {
|
||||
int id;
|
||||
String name;
|
||||
int parentId;
|
||||
CommonItem parent;
|
||||
String token;
|
||||
|
||||
|
||||
List<CommonItem> children = [];
|
||||
|
||||
String type = 'category';
|
||||
|
||||
CategoryComponent({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
@required this.parentId,
|
||||
this.children,
|
||||
this.parent
|
||||
});
|
||||
CategoryComponent.fromJson(Map json) {
|
||||
this.id = int.parse(json['id']);
|
||||
this.name = json['name'];
|
||||
this.parentId = json['parentId'];
|
||||
this.token = json['id'] + json['type'];
|
||||
}
|
||||
void addChildren(Object item) {
|
||||
if (item is CategoryComponent) {
|
||||
CategoryComponent cate = item;
|
||||
cate.parent = this;
|
||||
this.children.add(
|
||||
cate
|
||||
);
|
||||
}
|
||||
if (item is WidgetLeaf) {
|
||||
WidgetLeaf widget = item;
|
||||
widget.parent = this;
|
||||
this.children.add(
|
||||
widget
|
||||
);
|
||||
}
|
||||
}
|
||||
@override
|
||||
CommonItem getChild(String token) {
|
||||
return children.firstWhere((CommonItem item) => item.token == token, orElse: () => null);
|
||||
}
|
||||
|
||||
@override
|
||||
CommonItem find(String token, [CommonItem node]) {
|
||||
CommonItem ret;
|
||||
if (node !=null) {
|
||||
if (node.token == token) {
|
||||
return node;
|
||||
} else {
|
||||
// 循环到叶子节点, 返回 空
|
||||
if (node.children == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < node.children.length; i++) {
|
||||
CommonItem temp = this.find(token, node.children[i]);
|
||||
if (temp != null) {
|
||||
ret = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = find(token, this);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// 叶子节点
|
||||
class WidgetLeaf extends CommonItem {
|
||||
int id;
|
||||
String name;
|
||||
int parentId;
|
||||
String display; // 展示类型, 区分老的widget文件下的详情
|
||||
String author; // 文档负责人
|
||||
String path; // 路由地址
|
||||
String pageId; // 界面ID
|
||||
CommonItem parent;
|
||||
|
||||
String type = 'widget';
|
||||
WidgetLeaf({
|
||||
@required this.id,
|
||||
@required this.name,
|
||||
@required this.display,
|
||||
this.author,
|
||||
this.path,
|
||||
this.pageId
|
||||
});
|
||||
|
||||
WidgetLeaf.fromJson(Map json) {
|
||||
this.id = int.parse(json['id']);
|
||||
this.name = json['name'];
|
||||
this.display = json['display'];
|
||||
this.author = json['author'] ?? null;
|
||||
this.path = json['path'] ?? null;
|
||||
this.pageId = json['pageId'] ?? null;
|
||||
this.token = json['id'] + json['type'];
|
||||
}
|
||||
@override
|
||||
CommonItem getChild(String token) {
|
||||
return null;
|
||||
}
|
||||
@override
|
||||
addChildren(Object item) {
|
||||
// TODO: implement addChildren
|
||||
return null;
|
||||
}
|
||||
|
||||
CommonItem find(String token, [CommonItem node]){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class WidgetTree {
|
||||
static CategoryComponent buildWidgetTree(List json, [parent]){
|
||||
CategoryComponent current;
|
||||
if (parent != null) {
|
||||
current = parent;
|
||||
} else {
|
||||
current = CategoryComponent(id: 0, name: 'root', parentId: null, children: []);
|
||||
}
|
||||
json.forEach((item) {
|
||||
|
||||
// 归属分类级别
|
||||
if (['root', 'category'].indexOf(item['type']) != -1) {
|
||||
CategoryComponent cate = CategoryComponent.fromJson(item);
|
||||
if (cate.children != null) {
|
||||
buildWidgetTree(item['children'], cate);
|
||||
}
|
||||
current.addChildren(cate);
|
||||
} else {
|
||||
// 归属最后一层叶子节点
|
||||
WidgetLeaf cate = WidgetLeaf.fromJson(item);
|
||||
current.addChildren(cate);
|
||||
}
|
||||
});
|
||||
return current;
|
||||
}
|
||||
static CategoryComponent getCommonItemById(List<int> path, CategoryComponent root) {
|
||||
print("getCommonItemByPath $path");
|
||||
print("root $root");
|
||||
CommonItem childLeaf;
|
||||
int first = path.first;
|
||||
path = path.sublist(1);
|
||||
print("path:::: $path");
|
||||
if (path.length >= 0) {
|
||||
// childLeaf = root.getChild(path.first);
|
||||
}
|
||||
|
||||
|
||||
return childLeaf;
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ class WidgetName2Icon {
|
||||
static Map<String,dynamic> icons = {
|
||||
"Element":Icons.explicit,
|
||||
"Components":Icons.extension,
|
||||
"Themes":Icons.filter_b_and_w,
|
||||
"Theme":Icons.filter_b_and_w,
|
||||
"Form":Icons.table_chart,
|
||||
"Frame":Icons.aspect_ratio,
|
||||
"Media":Icons.subscriptions,
|
||||
|
@ -1,12 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
|
||||
import 'package:flutter_go/utils/shared_preferences.dart';
|
||||
|
||||
import '../model/widget.dart';
|
||||
|
||||
class Application {
|
||||
static Router router;
|
||||
static TabController controller;
|
||||
static SpUtil sharePeferences;
|
||||
static SpUtil sharePeference;
|
||||
static CategoryComponent widgetTree;
|
||||
|
||||
static Map<String, String> github = {
|
||||
'widgetsURL':'https://github.com/alibaba/flutter-go/blob/develop/lib/widgets/',
|
||||
|
@ -18,9 +18,9 @@ var homeHandler = new Handler(
|
||||
|
||||
var categoryHandler = new Handler(
|
||||
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
|
||||
String name = params["type"]?.first;
|
||||
String ids = params["ids"]?.first;
|
||||
|
||||
return new CategoryHome(name);
|
||||
return new CategoryHome(ids);
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Routes {
|
||||
});
|
||||
router.define(home, handler: homeHandler);
|
||||
|
||||
router.define('/category/:type', handler: categoryHandler);
|
||||
router.define('/category/:ids', handler: categoryHandler);
|
||||
router.define('/category/error/404', handler: widgetNotFoundHandler);
|
||||
router.define(loginPage, handler: loginPageHandler);
|
||||
router.define(codeView,handler:fullScreenCodeDialog);
|
||||
|
@ -50,4 +50,15 @@ class DataUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// 获取widget列表处的树型数据
|
||||
static Future<List> getWidgetTreeList() async {
|
||||
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
||||
|
||||
if (response['success']) {
|
||||
return response['data'];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class _MyHomePageState extends State<AppPage>
|
||||
_list
|
||||
// ..add(FirstPage())
|
||||
// ..add(MainPage())
|
||||
..add(WidgetPage(Provider.db))
|
||||
..add(WidgetPage())
|
||||
..add(CollectionPage())
|
||||
..add(FourthPage());
|
||||
}
|
||||
|
@ -6,28 +6,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_go/components/cate_card.dart';
|
||||
import 'package:flutter_go/model/cat.dart';
|
||||
|
||||
import 'package:flutter_go/routers/application.dart';
|
||||
|
||||
|
||||
class WidgetPage extends StatefulWidget {
|
||||
final db;
|
||||
final CatControlModel catModel;
|
||||
WidgetPage(this.db)
|
||||
: catModel = new CatControlModel(),
|
||||
super();
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
SecondPageState createState() => new SecondPageState(catModel);
|
||||
SecondPageState createState() => new SecondPageState();
|
||||
}
|
||||
|
||||
class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMixin{
|
||||
CatControlModel catModel;
|
||||
SecondPageState(this.catModel) : super();
|
||||
|
||||
SecondPageState() : super();
|
||||
|
||||
TextEditingController controller;
|
||||
String active = 'test';
|
||||
String data = '无';
|
||||
|
||||
List<Cat> categories = [];
|
||||
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
@ -35,25 +35,17 @@ class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMix
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
renderCats();
|
||||
}
|
||||
|
||||
void renderCats() {
|
||||
catModel.getList().then((List data) {
|
||||
if (data.isNotEmpty) {
|
||||
setState(() {
|
||||
categories = data;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Widget buildGrid() {
|
||||
// 存放最后的widget
|
||||
List<Widget> tiles = [];
|
||||
for (Cat item in categories) {
|
||||
|
||||
Application.widgetTree.children.forEach((dynamic item) {
|
||||
tiles.add(new CateCard(category: item));
|
||||
}
|
||||
});
|
||||
return new ListView(
|
||||
children: tiles,
|
||||
);
|
||||
@ -62,11 +54,7 @@ class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMix
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
if (categories.length == 0) {
|
||||
return ListView(
|
||||
children: <Widget>[new Container()],
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: Theme.of(context).backgroundColor,
|
||||
child: this.buildGrid(),
|
||||
|
@ -21,7 +21,7 @@ const String content1 = '''
|
||||
''';
|
||||
|
||||
class Demo extends StatefulWidget {
|
||||
static const String routeName = '/themes/Material/MaterialColor';
|
||||
static const String routeName = '/Themes/Material/MaterialColor';
|
||||
|
||||
_DemoState createState() => _DemoState();
|
||||
}
|
||||
|
16
pubspec.lock
16
pubspec.lock
@ -14,7 +14,7 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.0.8"
|
||||
bloc:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -192,7 +192,7 @@ packages:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.5"
|
||||
version: "0.12.3+1"
|
||||
meta:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -234,7 +234,7 @@ packages:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
version: "1.4.0"
|
||||
permission_handler:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -248,7 +248,7 @@ packages:
|
||||
name: quiver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.0.1"
|
||||
rxdart:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -274,7 +274,7 @@ packages:
|
||||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.5"
|
||||
version: "1.5.4"
|
||||
sqflite:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -295,7 +295,7 @@ packages:
|
||||
name: stream_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "1.6.8"
|
||||
string_scanner:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -323,7 +323,7 @@ packages:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.4"
|
||||
version: "0.2.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -346,5 +346,5 @@ packages:
|
||||
source: hosted
|
||||
version: "2.0.8"
|
||||
sdks:
|
||||
dart: ">=2.2.0 <3.0.0"
|
||||
dart: ">=2.1.0 <3.0.0"
|
||||
flutter: ">=1.2.1 <2.0.0"
|
||||
|
Reference in New Issue
Block a user