diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index c5bd9d3..e42a3c0 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -55,5 +55,14 @@ 获取访问相册权限更换头像 NSPhotoLibraryUsageDescription 获取访问相册权限更换头像 + io.flutter.embedded_views_preview + YES + LSRequiresIPhoneOS + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/lib/pages/setting_page/models/setting_page_style_item_model.dart b/lib/pages/setting_page/models/setting_page_style_item_model.dart index c166bc3..b79808a 100644 --- a/lib/pages/setting_page/models/setting_page_style_item_model.dart +++ b/lib/pages/setting_page/models/setting_page_style_item_model.dart @@ -19,12 +19,16 @@ class SettingPageStyleItemModel extends Object { @JsonKey(name: 'skip_identifier') String skipIdentifier; + @JsonKey(name: 'url') + String url; + SettingPageStyleItemModel( this.name, this.nameColor, this.desc, this.descColor, this.skipIdentifier, + this.url, ); factory SettingPageStyleItemModel.fromJson(Map srcJson) => diff --git a/lib/pages/setting_page/models/setting_page_style_item_model.g.dart b/lib/pages/setting_page/models/setting_page_style_item_model.g.dart index 996447a..c831197 100644 --- a/lib/pages/setting_page/models/setting_page_style_item_model.g.dart +++ b/lib/pages/setting_page/models/setting_page_style_item_model.g.dart @@ -14,6 +14,7 @@ SettingPageStyleItemModel _$SettingPageStyleItemModelFromJson( json['desc'] as String, json['desc_color'] as String, json['skip_identifier'] as String, + json['url'] as String, ); } @@ -25,4 +26,5 @@ Map _$SettingPageStyleItemModelToJson( 'desc': instance.desc, 'desc_color': instance.descColor, 'skip_identifier': instance.skipIdentifier, + 'url': instance.url, }; diff --git a/lib/pages/setting_page/setting_page.dart b/lib/pages/setting_page/setting_page.dart index d8bb7ec..a74e6b2 100644 --- a/lib/pages/setting_page/setting_page.dart +++ b/lib/pages/setting_page/setting_page.dart @@ -115,13 +115,40 @@ class _SettingContainerState extends State<_SettingContainer> { } Widget _createItem(SettingPageStyleItemModel item) { - return Container( - width: double.infinity, - height: 50, - color: Colors.white, - child: Row( - children: [Text(item.name), Text('aaaaa')], + return GestureDetector( + child: Container( + padding: EdgeInsets.only(left: 12.5, right: 12.5), + width: double.infinity, + height: 50, + color: Colors.white, + child: Row( + children: [ + Expanded( + child: Text( + item.name, + style: TextStyle( + fontSize: 13, + color: HexColor.fromHex(item.nameColor), + fontWeight: FontWeight.bold, + ), + ), + ), + Expanded( + child: Text( + item.desc, + textAlign: TextAlign.right, + style: TextStyle( + fontSize: 13, + color: HexColor.fromHex(item.descColor), + ), + ), + ), + ], + ), ), + onTap: () { + RouterUtil.route(item.toJson(), context); + }, ); } } diff --git a/lib/pages/webview/base_webview.dart b/lib/pages/webview/base_webview.dart new file mode 100644 index 0000000..e1c9bb6 --- /dev/null +++ b/lib/pages/webview/base_webview.dart @@ -0,0 +1,103 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:webview_flutter/webview_flutter.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class BaseWebview extends StatefulWidget { + final Map model; + + const BaseWebview( + this.model, { + Key key, + }) : super(key: key); + + @override + _BaseWebviewState createState() => _BaseWebviewState(); +} + +class _BaseWebviewState extends State { + String _url; + String _title; + WebViewController _webViewController; + + @override + void initState() { + _url = widget.model['url'] ?? ''; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: _createNav(), + body: Builder(builder: (BuildContext context) { + return WebView( + initialUrl: _url, + javascriptMode: JavascriptMode.unrestricted, + onWebViewCreated: (WebViewController webViewController) { + _webViewController = webViewController; + }, + navigationDelegate: (NavigationRequest request) { + return NavigationDecision.navigate; + }, + onPageStarted: (String url) { + print('Page started loading: $url'); + }, + onPageFinished: (String url) { + print('Page finished loading: $url'); + _webViewController.getTitle().then((title) { + _title = title; + setState(() {}); + }); + }, + gestureNavigationEnabled: true, + ); + }), + ); + } + +// 导航栏 + Widget _createNav() { + return CupertinoNavigationBar( + border: Border( + bottom: BorderSide( + width: 0.0, // One physical pixel. + style: BorderStyle.none, + ), + ), + backgroundColor: Colors.white, + leading: Navigator.canPop(context) + ? GestureDetector( + child: Container( + padding: EdgeInsets.zero, + child: Icon( + Icons.arrow_back_ios, + size: 20, + ), + ), + onTap: () { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + }, + ) + : Container(), + middle: Text( + _title ?? '', + style: TextStyle( + fontSize: 15, + color: HexColor.fromHex('333333'), + ), + ), + trailing: GestureDetector( + child: Icon( + Icons.refresh, + size: 20, + ), + onTap: () { + _webViewController.reload(); + }, + ), + ); + } +} diff --git a/lib/register.dart b/lib/register.dart index 5b2a21f..669fdd2 100644 --- a/lib/register.dart +++ b/lib/register.dart @@ -7,6 +7,7 @@ import 'package:zhiying_base_widget/pages/setting_page/setting_page.dart'; import 'package:zhiying_base_widget/pages/sreach_page/sreach_page.dart'; import 'package:zhiying_base_widget/pages/sreach_result_page/sreach_result_page.dart'; import 'package:zhiying_base_widget/pages/wallet_page/wallet_page.dart'; +import 'package:zhiying_base_widget/pages/webview/base_webview.dart'; import 'package:zhiying_base_widget/widgets/goods_details/footer/goods_details_footer_widget.dart'; import 'package:zhiying_base_widget/widgets/goods_details/price/goods_details_price_widget.dart'; import 'package:zhiying_base_widget/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart'; @@ -62,6 +63,8 @@ class BaseWidgetRegister { PageFactory.regist('pub.flutter.settings', (model) => SettingPage(model)); PageFactory.regist('pub.flutter.my_orders', (model) => OrdersPage(model)); + + PageFactory.regist('pub.flutter.url', (model) => BaseWebview(model)); } // 注册控件