diff --git a/README.md b/README.md index 2512a8a8..bd2f01d0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,25 @@ Language: [English](https://github.com/alibaba/flutter-go/blob/master/README-en. +## 运行方式 +- 查看一下版本号是否正确 +```dart + flutter --version +``` +- 运行以下命令查看是否需要安装其它依赖项来完成安装 +```dart + flutter doctor +``` +- 运行启动您的应用 +```dart + flutter packages get + flutter run +``` + +- 如果有其他问题,请参考 + - https://flutterchina.club/setup-macos/ + - https://flutter.dev/docs/get-started/install/macos ## Release安装包下载地址 diff --git a/lib/components/list_refresh.dart b/lib/components/list_refresh.dart index b4a13244..c5d3b0d8 100644 --- a/lib/components/list_refresh.dart +++ b/lib/components/list_refresh.dart @@ -174,6 +174,7 @@ class _ListRefreshState extends State { return widget.renderItem(index, items[index]); } } + return null; }, controller: _scrollController, ), diff --git a/lib/views/first_page/drawer_page.dart b/lib/views/first_page/drawer_page.dart index 52a9da0c..f0fc1be0 100644 --- a/lib/views/first_page/drawer_page.dart +++ b/lib/views/first_page/drawer_page.dart @@ -155,7 +155,7 @@ class _DrawerPageState extends State { size: 27.0, ), title: Text( - '搜索', + '全网搜', style: textStyle, ), onTap: () { @@ -223,7 +223,7 @@ class _DrawerPageState extends State { style: textStyle, ), onTap: () { - Share.share('https://github.com/alibaba/flutter-go'); + Share.share('https://flutter-go.pub/website/'); }, ), new Divider(), diff --git a/lib/views/first_page/first_page.dart b/lib/views/first_page/first_page.dart index 8c7f66ea..38840ba1 100644 --- a/lib/views/first_page/first_page.dart +++ b/lib/views/first_page/first_page.dart @@ -50,7 +50,9 @@ class FirstPageState extends State with AutomaticKeepAliveClientMixin Future getIndexListData([Map params]) async { - const juejin_flutter = 'https://timeline-merger-ms.juejin.im/v1/get_tag_entry?src=web&tagId=5a96291f6fb9a0535b535438'; + /// const juejin_flutter = 'https://timeline-merger-ms.juejin.im/v1/get_tag_entry?src=web&tagId=5a96291f6fb9a0535b535438'; + const juejin_flutter = 'https://fluttergo.pub:9527/juejin.im/v1/get_tag_entry?src=web&tagId=5a96291f6fb9a0535b535438'; + var pageIndex = (params is Map) ? params['pageIndex'] : 0; final _param = {'page':pageIndex,'pageSize':20,'sort':'rankIndex'}; var responseList = []; diff --git a/lib/views/first_page/main_page.dart b/lib/views/first_page/main_page.dart index 1630c994..9301ab55 100644 --- a/lib/views/first_page/main_page.dart +++ b/lib/views/first_page/main_page.dart @@ -6,18 +6,24 @@ import './sub_page.dart'; import './main_app_bar.dart'; import './search_page.dart'; import 'package:flutter_go/model/user_info.dart'; +import 'package:flutter_go/routers/application.dart' show Application; +import 'package:flutter_go/routers/routers.dart' show Routes; + +DefaultTabController _tabController; +TabBar _tabBar; class _Page { final String labelId; + final int labelIndex; - _Page(this.labelId); + _Page(this.labelId,this.labelIndex); } final List<_Page> _allPages = <_Page>[ - _Page('项目1'), - _Page('项目2'), - _Page('项目3'), - _Page('项目4'), + _Page('热门资讯', 1), + _Page('FG-官网', 2), + _Page('FG-web版', 3), + ///_Page('项目4'), ]; class MainPage extends StatelessWidget { @@ -27,12 +33,12 @@ class MainPage extends StatelessWidget { @override Widget build(BuildContext context) { print("MainPagess build......"); - return DefaultTabController( + _tabController = DefaultTabController( length: _allPages.length, child: Scaffold( - appBar: new MyAppBar( + appBar: MyAppBar( leading: Container( - child: new ClipOval( + child: ClipOval( child: Image.network( userInfo.id == 0?'https://hbimg.huabanimg.com/9bfa0fad3b1284d652d370fa0a8155e1222c62c0bf9d-YjG0Vt_fw658':userInfo.avatarPic, scale: 15.0, @@ -54,10 +60,8 @@ class MainPage extends StatelessWidget { ), ), body: TabBarViewLayout(), -// drawer: Drawer( -// child: MainLeftPage(), -// ), )); + return _tabController; } } @@ -69,35 +73,38 @@ void pushPage(BuildContext context, Widget page, {String pageName}) { class TabLayout extends StatelessWidget { @override Widget build(BuildContext context) { - return TabBar( + _tabBar = TabBar( isScrollable: true, //labelPadding: EdgeInsets.all(12.0), labelPadding: EdgeInsets.only(top: 12.0, left: 12.0, right: 12.0), indicatorSize: TabBarIndicatorSize.label, - tabs: _allPages - .map((_Page page) => - Tab(text: page.labelId)) - .toList(), + tabs: _allPages.map((_Page page) => Tab(text: page.labelId)).toList(), + onTap: (index) { + if (index == 1) { + DefaultTabController.of(context).animateTo(0); + Application.router.navigateTo(context, '${Routes.webViewPage}?title=${Uri.encodeComponent('Flutter Go 官方网站')}&url=${Uri.encodeComponent('https://flutter-go.pub')}'); + } else if (index == 2) { + +// new Future.delayed(const Duration(seconds: 1),(){ +// showAlertDialog(Application.globalContext); +// }); + + DefaultTabController.of(context).animateTo(0); + Application.router.navigateTo(context, '${Routes.webViewPage}?title=${Uri.encodeComponent('Flutter Go web版(H5)')}&url=${Uri.encodeComponent('https://flutter-go.pub/flutter_go_web')}'); + } + } ); + return _tabBar; } } class TabBarViewLayout extends StatelessWidget { Widget buildTabView(BuildContext context, _Page page) { - String labelId = page.labelId; - switch (labelId) { - case '项目1': + int labelIndex = page.labelIndex; + switch (labelIndex) { + case 1: return FirstPage(); break; - case '项目2': - return SubPage(); - break; - case '项目3': - return SubPage(); - break; - case '项目4': - return SubPage(); - break; default: return Container(); break; diff --git a/lib/views/first_page/search_page.dart b/lib/views/first_page/search_page.dart index 6d519738..e3d751c8 100644 --- a/lib/views/first_page/search_page.dart +++ b/lib/views/first_page/search_page.dart @@ -23,7 +23,7 @@ final _industryPage = Industry.IndustryPage(itemTitle: (state){ ), subtitle: Text(state.res[index].source), onTap: () { - // 在这里对选中的结果进行解析,因为我目前是用golang实现的,所以就没贴代码了。 + // 在这里对选中的结果进行解析 print(state.res[index].source); final itemTitle = state.res[index].title; final itemUrl = state.res[index].source; @@ -44,7 +44,7 @@ class SearchPage extends StatelessWidget { /// print('suggestion::${Industry.suggestion}'); return Scaffold( appBar: PreferredSize( - preferredSize: Size(double.infinity, 52), // 44 is the height + preferredSize: Size(double.infinity, 52), // is the height child: AppBar(title: searchBarPage) ), //body: ProgressView(), @@ -160,7 +160,7 @@ class _SearchBarPageState extends State { controller: controller, decoration: InputDecoration( contentPadding: EdgeInsets.only(top: 0.0), - hintText: '搜索全局flutter知识库', + hintText: '全网搜索 Flutter 相关知识库', hintStyle:TextStyle(fontSize: 12.0), border: InputBorder.none ), diff --git a/lib/views/home.dart b/lib/views/home.dart index 1355d7a5..862d66b2 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -12,6 +12,7 @@ import 'package:flutter_go/utils/shared_preferences.dart'; import 'package:flutter_go/views/first_page/first_page.dart'; import 'package:flutter_go/views/first_page/main_page.dart'; import 'package:fluro/fluro.dart'; +import 'package:flutter_go/views/user_page/user_page.dart'; import 'package:flutter_go/views/widget_page/widget_page.dart'; import 'package:flutter_go/views/welcome_page/fourth_page.dart'; import 'package:flutter_go/views/collection_page/collection_page.dart'; @@ -24,9 +25,7 @@ import 'package:flutter_go/model/search_history.dart'; import 'package:flutter_go/resources/widget_name_to_icon.dart'; import 'package:flutter_go/model/user_info.dart'; - class AppPage extends StatefulWidget { - final UserInformation userInfo; AppPage(this.userInfo); @@ -49,8 +48,9 @@ class _MyHomePageState extends State static List tabData = [ {'text': '业界动态', 'icon': Icon(Icons.language)}, {'text': 'WIDGET', 'icon': Icon(Icons.extension)}, - {'text': '组件收藏', 'icon': Icon(Icons.favorite)}, {'text': '关于手册', 'icon': Icon(Icons.import_contacts)}, + {'text': '个人中心', 'icon': Icon(Icons.account_circle)}, + ]; List _myTabs = []; @@ -72,8 +72,8 @@ class _MyHomePageState extends State // ..add(FirstPage()) ..add(MainPage(userInfo: widget.userInfo)) ..add(WidgetPage()) - ..add(CollectionPage()) - ..add(FourthPage()); + ..add(FourthPage()) + ..add(UserPage(userInfo: widget.userInfo)); } @override @@ -90,12 +90,11 @@ class _MyHomePageState extends State void onWidgetTap(WidgetPoint widgetPoint, BuildContext context) { String targetName = widgetPoint.name; - searchHistoryList - .add(SearchHistory(name: targetName, targetRouter: widgetPoint.routerName)); + searchHistoryList.add( + SearchHistory(name: targetName, targetRouter: widgetPoint.routerName)); print("searchHistoryList1 ${searchHistoryList.toString()}"); - Application.router.navigateTo( - context, widgetPoint.routerName, - transition: TransitionType.inFromRight); + Application.router.navigateTo(context, widgetPoint.routerName, + transition: TransitionType.inFromRight); } Widget buildSearchInput(BuildContext context) { @@ -121,10 +120,9 @@ class _MyHomePageState extends State } renderAppBar(BuildContext context, Widget widget, int index) { - if (index == 0) { - return null; + if (index == 1) { + return AppBar(title: buildSearchInput(context)); } - return AppBar(title: buildSearchInput(context)); } @override diff --git a/lib/views/issuse_message_page/issuse_message_page.dart b/lib/views/issuse_message_page/issuse_message_page.dart index 60a0cdde..c8c0a4b8 100644 --- a/lib/views/issuse_message_page/issuse_message_page.dart +++ b/lib/views/issuse_message_page/issuse_message_page.dart @@ -46,10 +46,10 @@ class _IssuesMessagePageState extends State { } _submit() { - String mk = notusMarkdown.encode(_delta); if (_title.trim().isEmpty) { _show('标题不能为空'); } else { + String mk = (_delta==null)?'No description provided.':notusMarkdown.encode(_delta); DataUtils.feedback({'title': _title, "body": mk},context).then((result) { _show('提交成功'); Navigator.maybePop(context); diff --git a/lib/views/login_page/login_page.dart b/lib/views/login_page/login_page.dart index 5be7d3c7..d0025764 100644 --- a/lib/views/login_page/login_page.dart +++ b/lib/views/login_page/login_page.dart @@ -67,7 +67,9 @@ class _LoginPageState extends State { setState(() { isLoading = true; }); - DataUtils.getUserInfo({'loginName': event.loginName,'token':event.token}).then((result) { + DataUtils.getUserInfo( + {'loginName': event.loginName, 'token': event.token}) + .then((result) { setState(() { isLoading = false; }); @@ -215,7 +217,7 @@ class _LoginPageState extends State { // 如果输入都检验通过,则进行登录操作 // Scaffold.of(context) // .showSnackBar(new SnackBar(content: new Text("执行登录操作"))); - //调用所有自孩子的save回调,保存表单内容 + //调用所有自孩子��save回调,保存表单内容 doLogin(); } }, @@ -234,22 +236,33 @@ class _LoginPageState extends State { setState(() { isLoading = false; }); - try { - _userInfoControlModel.deleteAll().then((result) { - // print('删除结果:$result'); - _userInfoControlModel - .insert(UserInfo(password: password, username: username)) - .then((value) { - print('存储成功:$value'); - Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (context) => AppPage(userResult)), - (route) => route == null); + if (userResult.runtimeType == UserInformation) { + try { + _userInfoControlModel.deleteAll().then((result) { + // print('删除结果:$result'); + _userInfoControlModel + .insert(UserInfo(password: password, username: username)) + .then((value) { + print('存储成功:$value'); + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute(builder: (context) => AppPage(userResult)), + (route) => route == null); + }); }); - }); - } catch (err) { - Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (context) => AppPage(userResult)), - (route) => route == null); + } catch (err) { + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute(builder: (context) => AppPage(userResult)), + (route) => route == null); + } + }else if(userResult.runtimeType == String){ + Fluttertoast.showToast( + msg: userResult, + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + timeInSecForIos: 1, + backgroundColor: Theme.of(context).primaryColor, + textColor: Colors.white, + fontSize: 16.0); } }).catchError((errorMsg) { setState(() { @@ -375,7 +388,8 @@ class _LoginPageState extends State { onPressed: () { Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute( - builder: (context) => AppPage(UserInformation(id: 0))), + builder: (context) => + AppPage(UserInformation(id: 0))), (route) => route == null); }, ) diff --git a/lib/views/user_page/user_page.dart b/lib/views/user_page/user_page.dart new file mode 100644 index 00000000..74924c58 --- /dev/null +++ b/lib/views/user_page/user_page.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_go/model/user_info.dart'; +import 'package:flutter_go/views/first_page/drawer_page.dart'; + +class UserPage extends StatefulWidget { + final UserInformation userInfo; + + UserPage({Key key, this.userInfo}) : super(key: key); + + @override + _UserPageState createState() => _UserPageState(); +} + +class _UserPageState extends State { + @override + Widget build(BuildContext context) { + print(widget.userInfo); + return Scaffold( + body: Container( + child: DrawerPage( + userInfo: widget.userInfo, + ), + ), + ); + } +} diff --git a/lib/views/web_page/web_view_page.dart b/lib/views/web_page/web_view_page.dart index 57b069b0..196ddb35 100644 --- a/lib/views/web_page/web_view_page.dart +++ b/lib/views/web_page/web_view_page.dart @@ -4,7 +4,7 @@ /// @Last Modified time: 2019-01-14 19:47:14 import 'dart:core'; - +import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; @@ -12,6 +12,7 @@ import 'package:flutter_go/model/collection.dart'; import 'package:flutter_go/event/event_bus.dart'; import 'package:flutter_go/event/event_model.dart'; import 'package:flutter_go/api/api.dart'; +import 'package:flutter_go/routers/application.dart' show Application; class WebViewPage extends StatefulWidget { final String url; @@ -21,15 +22,21 @@ class WebViewPage extends StatefulWidget { _WebViewPageState createState() => _WebViewPageState(); } -class _WebViewPageState extends State { +class _WebViewPageState extends State with AutomaticKeepAliveClientMixin{ + @override + bool get wantKeepAlive => true; + final flutterWebviewPlugin = new FlutterWebviewPlugin(); final GlobalKey _scaffoldKey = GlobalKey(); + @override void initState() { super.initState(); + dialog = dialogContext(false); flutterWebviewPlugin.onUrlChanged.listen((String url) { + print('url change:$url'); if (url.indexOf('loginSuccess') > -1) { String urlQuery = url.substring(url.indexOf('?') + 1); @@ -50,7 +57,7 @@ class _WebViewPageState extends State { .fire(UserGithubOAuthEvent(loginName, token, true)); } print('ready close'); - + flutterWebviewPlugin.close(); // 验证成功 } else if (url.indexOf('${Api.BASE_URL}loginFail') == 0) { @@ -61,21 +68,75 @@ class _WebViewPageState extends State { flutterWebviewPlugin.close(); } }); + flutterWebviewPlugin.onStateChanged.listen((state) async { + print('url state:$state'); + if(state.type == WebViewState.finishLoad) { + } + }); } + Widget dialogContext(bool isShow){ + if(!isShow){ + return Container(child:Text("")); + } + return Container( + height: 200, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text('分享到',style: TextStyle(fontSize:16,color: Colors.deepOrange)), + FlatButton( + child: Text('取消',style: TextStyle(fontSize:16,color: Colors.black45),), + onPressed: (){ + setState(() { + dialog = dialogContext(false); + + }); + } + ) + ] + ) + ]) + ); + } + + Container dialog; @override Widget build(BuildContext context) { return Scaffold( - key: _scaffoldKey, - appBar: AppBar( - title: Text(widget.title), - ), - body: WebviewScaffold( - url: widget.url, - withZoom: false, - withLocalStorage: true, - withJavascript: true, - ), - ); + key: _scaffoldKey, + appBar: AppBar( + title: Text(widget.title), +// actions: [ +// IconButton( +// icon: Icon(Icons.announcement), +// onPressed: () { +// /// flutterWebviewPlugin.evalJavascript("alert('Flutter Go H5 版本')"); +// setState(() { +// dialog = dialogContext(true); +// }); +// }, +// ) +// ], + ), + body: WebviewScaffold( + url: widget.url, + withZoom: true, + withLocalStorage: true, + withJavascript: true, + userAgent: "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36", + bottomNavigationBar:dialog, + initialChild: Container( + color: Colors.white, + child: const Center( + child: Text("Loading...."), + ), + ), + )); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 7dba5e7f..6401c44a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: flutter_spinkit: "^3.1.0" fluttertoast: ^3.1.0 dio: ^2.0.15 - flutter_webview_plugin: ^0.3.4 + flutter_webview_plugin: ^0.3.5 cookie_jar: ^1.0.0 # 日期格式化 intl: 0.15.7