diff --git a/README.md b/README.md index 0c9deff..f3ff6e8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,11 @@ # Flutter UI v1.0 -A new Flutter project. - -## Getting Started - -This project is a starting point for a Flutter application. - -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook) - -For help getting started with Flutter, view our -[online documentation](https://flutter.io/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +# 目录 +``` +__lib + __lang + __page + __router + __store + __widget +``` diff --git a/assets/json/widget_list.json b/assets/json/widget_list.json index 1e6bf62..3ebb1f1 100644 --- a/assets/json/widget_list.json +++ b/assets/json/widget_list.json @@ -7,35 +7,43 @@ "widgetList": [ { "code": 59101, - "name": "Row" + "name": "Row", + "key": "Row" }, { "code": 59103, - "name": "Column" + "name": "Column", + "key": "Column" }, { "code": 59105, - "name": "Container" + "name": "Container", + "key": "Container" }, { "code": 57897, - "name": "Center" + "name": "Center", + "key": "Center" }, { "code": 59497, - "name": "Padding" + "name": "Padding", + "key": "Padding" }, { "code": 59497, - "name": "Stack" + "name": "Stack", + "key": "Stack" }, { "code": 59497, - "name": "Expanded" + "name": "Expanded", + "key": "Expanded" }, { "code": 59497, - "name": "Align" + "name": "Align", + "key": "Align" } ] }, @@ -44,46 +52,39 @@ "code": 58353, "widgetList": [ { - "name": "FittedBox" + "name": "FittedBox", + "key": "FittedBox" }, { - "name": "ConstrainedBox" + "name": "ConstrainedBox", + "key": "ConstrainedBox" }, { - "name": "DecoratedBox" + "name": "DecoratedBox", + "key": "DecoratedBox" }, { - "name": "LimitedBox" + "name": "LimitedBox", + "key": "LimitedBox" }, { - "name": "RotatedBox" + "name": "RotatedBox", + "key": "RotatedBox" }, { - "name": "Table" + "name": "Table", + "key": "Table" } ] }, { - "typeName": "form", + "typeName": "scrollview", "code": 58353, "widgetList": [ { - "name": "FittedBox" - }, - { - "name": "ConstrainedBox" - }, - { - "name": "DecoratedBox" - }, - { - "name": "LimitedBox" - }, - { - "name": "RotatedBox" - }, - { - "name": "Table" + "code": 59673, + "name": "GridView", + "key": "scrollview_gridview" } ] } diff --git a/lib/page/baseComp.dart b/lib/components/baseComp.dart similarity index 100% rename from lib/page/baseComp.dart rename to lib/components/baseComp.dart diff --git a/lib/components/markdownComp.dart b/lib/components/markdownComp.dart new file mode 100644 index 0000000..e360176 --- /dev/null +++ b/lib/components/markdownComp.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart' as md; + +class MarkDownComp extends StatelessWidget { + final String data; + MarkDownComp(this.data); + + @override + Widget build(BuildContext build ) { + return md.MarkdownBody(data: this.data); + } +} \ No newline at end of file diff --git a/lib/components/widgetComp.dart b/lib/components/widgetComp.dart new file mode 100644 index 0000000..ecac97d --- /dev/null +++ b/lib/components/widgetComp.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:efox_flutter/store/STORE.dart'; +import 'package:efox_flutter/components/markdownComp.dart'; + +class WidgetComp extends StatelessWidget { + final dynamic modelChild; + final String title; + + WidgetComp({Key key, this.title, @required this.modelChild}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return STORE.connect(builder: (context, child, model) { + List _list = this.modelChild(context, child, model); + List<Widget> _bodyList = []; + _list.forEach((item) { + if (item.runtimeType == String) { + _bodyList.add(MarkDownComp(item)); + } else { + _bodyList.add(item); + } + }); + return Scaffold( + appBar: AppBar( + title: Text(this.title), + ), + body: ListView( + padding: EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0), + shrinkWrap: true, + children: _bodyList, + ), + ); + }); + } +} diff --git a/lib/page/tabbar/index.dart b/lib/page/tabbar/index.dart index 071cee3..ba26c08 100644 --- a/lib/page/tabbar/index.dart +++ b/lib/page/tabbar/index.dart @@ -56,7 +56,12 @@ class _ComponentsPageState extends State<ComponentsPage> (index) { return Container( decoration: BoxDecoration( - border: Border.all(color: Colors.deepOrange, width: 0.4), + border: Border( + bottom: BorderSide( + width: .1, + color: Colors.orange.shade300, + ) + ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -70,8 +75,8 @@ class _ComponentsPageState extends State<ComponentsPage> color: Colors.deepOrange, ), onPressed: () { - print('idndex, $index ${routesMap()['ScrollViewGridView']}'); - Navigator.pushNamed(context, routesMap()['ScrollViewGridView']); + String _key = _tmpWidgetList[index].key; + Navigator.pushNamed(context, routesMap()['${_key}']); }, ), Text(_tmpWidgetList[index].name), diff --git a/lib/page/widgets_demo/index.dart b/lib/page/widgets_demo/index.dart deleted file mode 100644 index e69de29..0000000 diff --git a/lib/router/scrollview/index.dart b/lib/router/scrollview/index.dart index ca3a788..4e90b7a 100644 --- a/lib/router/scrollview/index.dart +++ b/lib/router/scrollview/index.dart @@ -1,14 +1,20 @@ import 'package:flutter/widgets.dart'; -import 'package:efox_flutter/widget/scrollview/gridview.dart'; +import 'package:efox_flutter/widget/scrollview/GridView/gridview.dart'; + +const nameSpaces = 'scrollview_'; +const gridview = nameSpaces + 'gridview'; + +const routerMaps = { + gridview: '/widget/scrollview/GridView/gridview', +}; Map<String, WidgetBuilder> getScrollViewRoutersConfig(BuildContext context) { return { - '/widget/scrollview/gridview': (context) => GridViewDemo(), + routerMaps[gridview] : (context) => GridViewDemo(), }; } -const nameSpaces = 'ScrollView'; Map<String, String> routesMapScrollView = { - nameSpaces + 'GridView': '/widget/scrollview/gridview', + gridview: routerMaps[gridview], }; diff --git a/lib/store/http.dart b/lib/store/http.dart new file mode 100644 index 0000000..d6e746a --- /dev/null +++ b/lib/store/http.dart @@ -0,0 +1,43 @@ +import 'package:dio/dio.dart'; +import 'dart:io'; + +class RestApi { + RestApi(); + static Dio _dio; + static getDio([options]) { + if (RestApi._dio != null) { + return RestApi._dio; + } + Dio dio = new Dio(options); + // proxy + dio.onHttpClientCreate = (HttpClient client) { + // client.findProxy = (uri) { + // print(Index.proxyUrl); + // return Index.proxyUrl; + // }; + }; + RestApi._dio = dio; + return dio; + } + + static request({method, url, data}) async { + Response<dynamic> response; + if (method == 'get') { + response = await RestApi.getDio().get(url, data: data); + } else { + response = await RestApi.getDio().post(url, data: data); + } + return response.data; + } + + // dio.post('/test', data: {id:'123'}) + static post(url, [data]) async{ + return await RestApi.getDio().post(url, data: data); + } + + // dio.get('/test', {data: {}}) + // dio.get('/test?id=123') + static get(url, [data]) async { + return await RestApi.getDio().get(url, data: data); + } +} diff --git a/lib/store/objects/widget_list.dart b/lib/store/objects/widget_list.dart index 18997e6..086dd2d 100644 --- a/lib/store/objects/widget_list.dart +++ b/lib/store/objects/widget_list.dart @@ -1,10 +1,12 @@ class ItemInfo extends Object { int code; String name; + String key; ItemInfo.fromJson(Map<String, dynamic> json) { code = json['code']; name = json['name']; + key = json['key']; } } diff --git a/lib/widget/e_image.dart b/lib/widget/e_image.dart deleted file mode 100644 index fcbc7cd..0000000 --- a/lib/widget/e_image.dart +++ /dev/null @@ -1 +0,0 @@ -//图片组件 diff --git a/lib/widget/scrollview/GridView/gridview.dart b/lib/widget/scrollview/GridView/gridview.dart new file mode 100644 index 0000000..88dd9db --- /dev/null +++ b/lib/widget/scrollview/GridView/gridview.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:efox_flutter/components/widgetComp.dart'; +import 'package:efox_flutter/store/http.dart'; +import 'intro.dart'; + +class GridViewDemo extends StatefulWidget { + @override + _GridViewDemoState createState() => new _GridViewDemoState(); +} + +class _GridViewDemoState extends State<GridViewDemo> { + String mdList = ''; + @override + void initState() { + super.initState(); + this.initMd (); + } + initMd () async { + dynamic res = await RestApi.get('https://wanwusangzhi.github.io/WebStudy/readme.md'); + setState(() { + this.mdList = res.toString(); + }); + } + @override + Widget build(BuildContext context) { + return WidgetComp( + title: 'GridViewDemo', + modelChild: (context, child, model) { + return [ + md_01, + mdList, + Container( + color: Colors.teal.shade700, + alignment: Alignment.center, + child: Text('Hello WorldHello WorldHello WorldHello WorldHello World', style: Theme.of(context).textTheme.display1.copyWith(color: Colors.white)), + ), + ]; + }, + ); + } +} diff --git a/lib/widget/scrollview/GridView/intro.dart b/lib/widget/scrollview/GridView/intro.dart new file mode 100644 index 0000000..48f56f6 --- /dev/null +++ b/lib/widget/scrollview/GridView/intro.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; + +const md_01 = """ +### ***GridView*** + +> GridView可创建一个二维的网格布局 +``` + + GridView({ + Key key, + Axis scrollDirection: Axis.vertical, + bool reverse: false, + ScrollController controller, + bool primary, + ScrollPhysics physics, + bool shrinkWrap: false, + EdgeInsetsGeometry padding, + @required SliverGridDelegate gridDelegate, + bool addAutomaticKeepAlives: true, + bool addRepaintBoundaries: true, + bool addSemanticIndexes: true, + double cacheExtent, + List<Widget> children: const [], + int semanticChildCount +}) +``` + +"""; \ No newline at end of file diff --git a/lib/widget/scrollview/gridview.dart b/lib/widget/scrollview/gridview.dart deleted file mode 100644 index 9b64782..0000000 --- a/lib/widget/scrollview/gridview.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:efox_flutter/page/baseComp.dart'; - -class GridViewDemo extends StatefulWidget { - @override - _GridViewDemoState createState() => new _GridViewDemoState(); -} - -class _GridViewDemoState extends State<GridViewDemo> { - @override - Widget build(BuildContext context) { - return BaseComp( - title: 'GridViewDemo', - child: (context, child, model) { - return Center( - child: Text( - 'Griview', - style: TextStyle( - fontSize: 22.0, - ), - ), - ); - }, - ); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index 499bfc2..1801f84 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: dio: ^1.0.12 cached_network_image: ^0.5.1 intl: ^0.15.7 + flutter_markdown: ^0.2.0 dev_dependencies: flutter_test: