├── .gitignore ├── .idea ├── checkstyle-idea.xml ├── codeStyles │ └── Project.xml ├── libraries │ ├── Dart_Packages.xml │ ├── Dart_SDK.xml │ ├── Flutter_Plugins.xml │ └── Flutter_for_Android.xml ├── misc.xml ├── modules.xml ├── runConfigurations │ └── main_dart.xml ├── vcs.xml └── workspace.xml ├── .metadata ├── README.md ├── android ├── .gitignore ├── .idea │ ├── caches │ │ └── build_file_checksums.ser │ ├── checkstyle-idea.xml │ ├── codeStyles │ │ └── Project.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── app │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── jzhu │ │ │ └── flutterstudy │ │ │ ├── MainActivity.java │ │ │ ├── OneActivity.java │ │ │ ├── TwoActivity.java │ │ │ └── plugin │ │ │ ├── FlutterPluginAMap.java │ │ │ ├── FlutterPluginCounter.java │ │ │ ├── FlutterPluginJumpToAct.java │ │ │ └── FlutterPluginPermissions.java │ │ └── res │ │ ├── drawable │ │ └── launch_background.xml │ │ ├── layout │ │ ├── activity_one.xml │ │ └── activity_two.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ └── styles.xml ├── build.gradle ├── building_system │ └── jz.jks ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── flutter_study.iml ├── flutter_study_android.iml ├── images ├── 2.0x │ └── ic_assignment_ind_36pt.png ├── 3.0x │ └── ic_assignment_ind_36pt.png ├── ic_assignment_ind_36pt.png └── lifecycle.png ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── Podfile.lock ├── Runner.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Runner │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-1024x1024@1x.png │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ └── Icon-App-83.5x83.5@2x.png │ └── LaunchImage.imageset │ │ ├── Contents.json │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x.png │ │ ├── LaunchImage@3x.png │ │ └── README.md │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── main.m ├── lib ├── common │ ├── constant.dart │ └── widget │ │ ├── common_webview.dart │ │ └── progreess_dialog.dart ├── main.dart ├── model │ ├── ai_model.dart │ ├── base_model.dart │ ├── fl_model.dart │ ├── hot_news_model.dart │ ├── inherited_test_model.dart │ └── search_model.dart ├── mvp │ ├── mvp.dart │ ├── presenter │ │ ├── ai_presenter.dart │ │ ├── ai_presenter_impl.dart │ │ ├── fl_presenter.dart │ │ └── fl_presenter_impl.dart │ └── repository │ │ ├── ai_repository.dart │ │ ├── ai_repository_impl.dart │ │ ├── fl_repository.dart │ │ └── fl_repository_impl.dart ├── theme │ └── custom_theme.dart ├── util │ ├── dio_factory.dart │ ├── fix_url_util.dart │ └── routes_util.dart └── widget │ ├── advanced_page.dart │ ├── architecture_page.dart │ ├── demo_admob │ └── admob_page.dart │ ├── demo_animation │ └── animation_page.dart │ ├── demo_base_widget │ ├── base_widget_page.dart │ └── container_page.dart │ ├── demo_common │ ├── hide_and_show_page.dart │ └── test.dart │ ├── demo_custom_toast │ ├── blinking_toast.dart │ ├── show_notification.dart │ └── toast_page.dart │ ├── demo_database │ └── data_page.dart │ ├── demo_gesture │ ├── dismissed_page.dart │ ├── drag_page.dart │ ├── gesture_page.dart │ └── multi_touch_page.dart │ ├── demo_inherited │ ├── inherited_w_page.dart │ ├── inherited_w_test_a.dart │ ├── inherited_w_test_b.dart │ └── inherited_w_test_c.dart │ ├── demo_key │ └── globalkey_form_page.dart │ ├── demo_lifecycle │ └── lifecycle_page.dart │ ├── demo_loadimg │ ├── loadIm_by_loc_page.dart │ ├── loadImg_by_net_page.dart │ └── loadImg_page.dart │ ├── demo_localizations │ └── localizations_study.dart │ ├── demo_native │ └── channel_page.dart │ ├── demo_network │ └── network_page.dart │ ├── demo_notification │ └── notification_page.dart │ ├── demo_route │ ├── route_page.dart │ ├── route_page_with_value.dart │ └── route_page_with_value_one.dart │ ├── demo_simple_bloc │ ├── search_bloc.dart │ └── search_page.dart │ ├── demo_simple_redux │ ├── count_middleware.dart │ ├── count_redux.dart │ ├── count_redux_page.dart │ ├── redux_w_test_a.dart │ ├── redux_w_test_b.dart │ └── redux_w_test_c.dart │ ├── demo_stream │ └── streams_page.dart │ ├── drawer_page.dart │ ├── home_page.dart │ ├── tab_android_page.dart │ ├── tab_girl_page.dart │ └── tab_ios_page.dart ├── pubspec.lock ├── pubspec.yaml ├── screenshot ├── 1.jpeg ├── 10.jpeg ├── 11.jpeg ├── 12.jpeg ├── 13.jpeg ├── 14.jpeg ├── 15.jpeg ├── 16.jpeg ├── 17.jpeg ├── 18.jpeg ├── 19.jpeg ├── 20.png ├── 3.jpeg ├── 4.png ├── 5.jpeg ├── 6.jpeg ├── 8.jpeg └── 9.jpeg └── test └── widget_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | 9 | .flutter-plugins 10 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/libraries/Dart_SDK.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_Plugins.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Flutter_for_Android.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations/main_dart.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: f9bb4289e9fd861d70ae78bcc3a042ef1b35cc9d 8 | channel: beta 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_study 2 | 3 | 感谢 http://gank.io 提供的api帮助完成这个demo 4 | 该项目完全开源,单纯为了学习与交流,希望大家喜欢,多多提意见。 5 | 后续会将未来学到的新知识点用到该项目,持续更新 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ## 知识点(每一个都有一个独立的例子) 15 | 1.基础布局 16 | 2.数据请求 17 | 3.MVP实现 18 | 4.上拉加载(监测到最底端直接刷新,待优化),下拉刷新 19 | 5.主题学习 20 | 6.路由 21 | 7.drawer 22 | 8.数据存储三种方式(文件,SharedPreference,sqflite) 23 | 9.手势 24 | 10.图片加载 25 | 11.生命周期 26 | 12.网络请求(dio,http,原生) 27 | 13.多点触控 28 | 14.InheritedWidget 29 | 15.TabBarView & TabBar ,切换的时候,每次都会执行initState。 30 | 16.GlobalKey(简单使用) 31 | 17.国际化 32 | 18.Notification自下而上传递数据 33 | 19.显示/隐藏widget 34 | 20.drag 35 | 21.Animation 36 | 22.StreamController 37 | 23.[Business Logic Component](https://medium.com/lacolaco-blog/bloc-design-pattern-with-angular-1c2f0339f6a3) 38 | 24.Simple Redux & Simple BLoC 39 | 25.Channel(目前使用Android设备学习,高德,权限) 40 | 41 | 42 | ## 部分问题记录 43 | 1.[SnackBar弹不出怎么办](https://www.jianshu.com/p/6520e0173049) 44 | 2.[如何监听实体返回键和AppBar返回键](https://www.jianshu.com/p/f9f496652807) 45 | 3.[刘海和状态栏没有填充当前主题颜色怎么办](https://www.jianshu.com/p/90cd38aeee65) 46 | 47 | 48 | ## 第三方库 49 | 第三方库搜索: 50 | https://pub.dartlang.org/ 51 | 52 | 持久化 53 | sqflite:https://pub.dartlang.org/packages/sqflite 54 | shared_preferences:https://pub.dartlang.org/packages/shared_preferences 55 | path_provider:https://pub.dartlang.org/packages/path_provider 56 | 57 | 图片加载 58 | cached_network_image:https://pub.dartlang.org/packages/cached_network_image 59 | transparent_image:https://pub.dartlang.org/packages/transparent_image 60 | 61 | 网络请求 62 | dio:https://pub.dartlang.org/packages/dio 63 | http:https://pub.dartlang.org/packages/http 64 | 65 | WebView 66 | flutter_webview_plugin:https://pub.dartlang.org/packages/flutter_webview_plugin 67 | 68 | ## 推荐资源 69 | Flutter英文网:https://flutter.io 70 | Flutter中文网:https://flutterchina.club 71 | Flutter社区:http://flutter-dev.cn/ 72 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.class 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | GeneratedPluginRegistrant.java 11 | -------------------------------------------------------------------------------- /android/.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhujian1989/flutter_study/03d5ae9d8ae68582db3ee293ee676a94d4edbd9c/android/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /android/.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /android/.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /android/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | -------------------------------------------------------------------------------- /android/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /android/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | apply plugin: 'com.android.application' 15 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 16 | 17 | android { 18 | compileSdkVersion 27 19 | 20 | lintOptions { 21 | disable 'InvalidPackage' 22 | } 23 | 24 | defaultConfig { 25 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 26 | applicationId "com.jzhu.flutterstudy" 27 | minSdkVersion 16 28 | targetSdkVersion 27 29 | versionCode 1 30 | versionName "1.0" 31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 32 | 33 | ndk { abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","arm64-v8a","x86_64" } 34 | 35 | } 36 | 37 | signingConfigs { 38 | release { 39 | keyAlias 'jz' 40 | keyPassword '123456' 41 | storeFile file('../building_system/jz.jks') 42 | storePassword '123456' 43 | } 44 | } 45 | 46 | buildTypes { 47 | release { 48 | // minifyEnabled true 49 | signingConfig signingConfigs.release 50 | // proguardFile 'proguard-rules.pro' 51 | } 52 | debug { 53 | signingConfig signingConfigs.debug 54 | } 55 | } 56 | } 57 | 58 | flutter { 59 | source '../..' 60 | } 61 | 62 | dependencies { 63 | implementation fileTree(dir: 'libs', include: ['*.jar']) 64 | testImplementation 'junit:junit:4.12' 65 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 66 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 67 | implementation 'io.reactivex.rxjava2:rxjava:2.1.1' 68 | implementation 'com.amap.api:location:4.2.0' 69 | implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar' 70 | // implementation 'com.android.support:support-compat:27.1.1' 71 | // implementation 'com.android.support:appcompat-v7:27.1.1' 72 | // implementation 'com.android.support:support-fragment:27.1.1' 73 | // implementation 'com.android.support:support-core-utils:27.1.1' 74 | 75 | } 76 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 37 | 41 | 48 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy; 2 | 3 | import android.os.Bundle; 4 | import com.jzhu.flutterstudy.plugin.FlutterPluginAMap; 5 | import com.jzhu.flutterstudy.plugin.FlutterPluginCounter; 6 | import com.jzhu.flutterstudy.plugin.FlutterPluginJumpToAct; 7 | import com.jzhu.flutterstudy.plugin.FlutterPluginPermissions; 8 | import io.flutter.app.FlutterActivity; 9 | import io.flutter.plugin.common.PluginRegistry; 10 | import io.flutter.plugins.GeneratedPluginRegistrant; 11 | 12 | public class MainActivity extends FlutterActivity { 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | GeneratedPluginRegistrant.registerWith(this); 18 | registerCustomPlugin(this); 19 | } 20 | 21 | private static void registerCustomPlugin(PluginRegistry registrar) { 22 | 23 | FlutterPluginJumpToAct.registerWith(registrar.registrarFor(FlutterPluginJumpToAct.CHANNEL)); 24 | 25 | FlutterPluginCounter.registerWith(registrar.registrarFor(FlutterPluginCounter.CHANNEL)); 26 | 27 | FlutterPluginPermissions.registerWith(registrar.registrarFor(FlutterPluginPermissions.CHANNEL)); 28 | 29 | FlutterPluginAMap.registerWith(registrar.registrarFor(FlutterPluginAMap.EVENT_CHANNEL)); 30 | 31 | } 32 | 33 | 34 | 35 | 36 | } 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/OneActivity.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class OneActivity extends Activity implements View.OnClickListener { 10 | 11 | private Button mGoFlutterBtn; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | setContentView(R.layout.activity_one); 18 | 19 | mGoFlutterBtn = findViewById(R.id.go_flutter); 20 | 21 | mGoFlutterBtn.setOnClickListener(this); 22 | 23 | } 24 | 25 | @Override 26 | public void onClick(View view) { 27 | switch (view.getId()) { 28 | case R.id.go_flutter: 29 | Intent intent = new Intent(this, MainActivity.class); 30 | startActivity(intent); 31 | break; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/TwoActivity.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | 7 | public class TwoActivity extends Activity{ 8 | 9 | private TextView mTextView; 10 | 11 | public static final String VALUE = "value"; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | setContentView(R.layout.activity_two); 18 | 19 | mTextView = findViewById(R.id.text); 20 | 21 | String text = getIntent().getStringExtra(VALUE); 22 | 23 | mTextView.setText(text); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/plugin/FlutterPluginAMap.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy.plugin; 2 | 3 | import android.app.Activity; 4 | import android.util.Log; 5 | import com.amap.api.location.AMapLocation; 6 | import com.amap.api.location.AMapLocationClient; 7 | import com.amap.api.location.AMapLocationClientOption; 8 | import com.amap.api.location.AMapLocationListener; 9 | import io.flutter.plugin.common.EventChannel; 10 | import io.flutter.plugin.common.PluginRegistry; 11 | 12 | import java.util.HashMap; 13 | 14 | public class FlutterPluginAMap implements EventChannel.StreamHandler { 15 | 16 | public static String EVENT_CHANNEL = "com.jzhu.amap.loc/plugin"; 17 | 18 | public static String METHOD_CHANNEL = "com.jzhu.amap.fun/plugin"; 19 | 20 | private static EventChannel mEventChannel; 21 | 22 | private Activity mActivity; 23 | 24 | private AMapLocationClient mlocationClient; 25 | 26 | private AMapLocationClientOption mLocationOption = null; 27 | 28 | private EventChannel.EventSink mEventSink; 29 | 30 | private HashMap mLocation = new HashMap<>(); 31 | 32 | private static FlutterPluginAMap instance; 33 | 34 | private FlutterPluginAMap(Activity activity) { 35 | this.mActivity = activity; 36 | initAMap(); 37 | } 38 | 39 | public static void registerWith(PluginRegistry.Registrar registrar) { 40 | 41 | if (null == instance) { 42 | instance = new FlutterPluginAMap(registrar.activity()); 43 | } 44 | 45 | mEventChannel = new EventChannel(registrar.messenger(), EVENT_CHANNEL); 46 | mEventChannel.setStreamHandler(instance); 47 | 48 | } 49 | 50 | 51 | private void initAMap() { 52 | mlocationClient = new AMapLocationClient(mActivity); 53 | mLocationOption = new AMapLocationClientOption(); 54 | mlocationClient.setLocationListener(new AMapLocationListener() { 55 | @Override 56 | public void onLocationChanged(AMapLocation aMapLocation) { 57 | if (aMapLocation != null) { 58 | if (aMapLocation.getErrorCode() == 0) { 59 | //定位成功回调信息,设置相关消息 60 | // aMapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见定位类型表 61 | // aMapLocation.getLatitude();//获取纬度 62 | // aMapLocation.getLongitude();//获取经度 63 | // aMapLocation.getAccuracy();//获取精度信息 64 | // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 65 | // Date date = new Date(aMapLocation.getTime()); 66 | // df.format(date);//定位时间 67 | 68 | mLocation.put("province", aMapLocation.getProvince()); 69 | mLocation.put("city", aMapLocation.getCity()); 70 | mLocation.put("latitude", aMapLocation.getLatitude()); 71 | mLocation.put("longitude", aMapLocation.getLongitude()); 72 | mLocation.put("address", aMapLocation.getAddress()); 73 | 74 | if (null != mEventSink) { 75 | mEventSink.success(mLocation); 76 | } 77 | } 78 | else { 79 | //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。 80 | Log.e("zj", "location Error, ErrCode:" 81 | + aMapLocation.getErrorCode() + ", errInfo:" 82 | + aMapLocation.getErrorInfo()); 83 | } 84 | } 85 | } 86 | }); 87 | mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); 88 | mLocationOption.setInterval(10 * 1000); 89 | mlocationClient.setLocationOption(mLocationOption); 90 | mlocationClient.startLocation(); 91 | 92 | } 93 | 94 | @Override 95 | public void onListen(Object o, final EventChannel.EventSink eventSink) { 96 | 97 | mEventSink = eventSink; 98 | 99 | } 100 | 101 | @Override 102 | public void onCancel(Object o) { 103 | 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/plugin/FlutterPluginCounter.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy.plugin; 2 | 3 | import android.app.Activity; 4 | import android.util.Log; 5 | import io.flutter.plugin.common.BasicMessageChannel; 6 | import io.flutter.plugin.common.EventChannel; 7 | import io.flutter.plugin.common.PluginRegistry; 8 | import io.flutter.plugin.common.StringCodec; 9 | import io.reactivex.Observable; 10 | import io.reactivex.Observer; 11 | import io.reactivex.disposables.Disposable; 12 | 13 | import java.util.concurrent.TimeUnit; 14 | 15 | public class FlutterPluginCounter implements EventChannel.StreamHandler { 16 | 17 | public static String CHANNEL = "com.jzhu.counter/plugin"; 18 | 19 | static EventChannel channel; 20 | 21 | private Activity activity; 22 | 23 | // static BasicMessageChannel basicMessageChannel; 24 | 25 | private FlutterPluginCounter(Activity activity) { 26 | this.activity = activity; 27 | } 28 | 29 | public static void registerWith(PluginRegistry.Registrar registrar) { 30 | channel = new EventChannel(registrar.messenger(), CHANNEL); 31 | FlutterPluginCounter instance = new FlutterPluginCounter(registrar.activity()); 32 | channel.setStreamHandler(instance); 33 | // basicMessageChannel = new BasicMessageChannel ("foo", StringCodec.INSTANCE); 34 | } 35 | 36 | @Override 37 | public void onListen(Object o, final EventChannel.EventSink eventSink) { 38 | 39 | Observable.interval(1000, TimeUnit.MILLISECONDS).subscribe(new Observer() { 40 | @Override 41 | public void onSubscribe(Disposable d) { 42 | 43 | } 44 | 45 | @Override 46 | public void onNext(Long aLong) { 47 | eventSink.success(aLong.intValue()); 48 | } 49 | 50 | @Override 51 | public void onError(Throwable e) { 52 | eventSink.error("计时器异常", "异常", e.getMessage()); 53 | } 54 | 55 | @Override 56 | public void onComplete() { 57 | } 58 | }); 59 | 60 | } 61 | 62 | @Override 63 | public void onCancel(Object o) { 64 | Log.i("FlutterPluginCounter", "FlutterPluginCounter:onCancel"); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/plugin/FlutterPluginJumpToAct.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy.plugin; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import com.jzhu.flutterstudy.OneActivity; 6 | import com.jzhu.flutterstudy.TwoActivity; 7 | import io.flutter.plugin.common.MethodCall; 8 | import io.flutter.plugin.common.MethodChannel; 9 | import io.flutter.plugin.common.PluginRegistry; 10 | 11 | public class FlutterPluginJumpToAct implements MethodChannel.MethodCallHandler { 12 | 13 | public static String CHANNEL = "com.jzhu.jump/plugin"; 14 | 15 | static MethodChannel channel; 16 | 17 | private Activity activity; 18 | 19 | private FlutterPluginJumpToAct(Activity activity) { 20 | this.activity = activity; 21 | } 22 | 23 | public static void registerWith(PluginRegistry.Registrar registrar) { 24 | channel = new MethodChannel(registrar.messenger(), CHANNEL); 25 | FlutterPluginJumpToAct instance = new FlutterPluginJumpToAct(registrar.activity()); 26 | //setMethodCallHandler在此通道上接收方法调用的回调 27 | channel.setMethodCallHandler(instance); 28 | } 29 | 30 | @Override 31 | public void onMethodCall(MethodCall call, MethodChannel.Result result) { 32 | 33 | //通过MethodCall可以获取参数和方法名,然后再寻找对应的平台业务,本案例做了2个跳转的业务 34 | 35 | //接收来自flutter的指令oneAct 36 | if (call.method.equals("oneAct")) { 37 | 38 | //跳转到指定Activity 39 | Intent intent = new Intent(activity, OneActivity.class); 40 | activity.startActivity(intent); 41 | 42 | //返回给flutter的参数 43 | result.success("success"); 44 | } 45 | //接收来自flutter的指令twoAct 46 | else if (call.method.equals("twoAct")) { 47 | 48 | //解析参数 49 | String text = call.argument("flutter"); 50 | 51 | //带参数跳转到指定Activity 52 | Intent intent = new Intent(activity, TwoActivity.class); 53 | intent.putExtra(TwoActivity.VALUE, text); 54 | activity.startActivity(intent); 55 | 56 | //返回给flutter的参数 57 | result.success("success"); 58 | } 59 | else { 60 | result.notImplemented(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/jzhu/flutterstudy/plugin/FlutterPluginPermissions.java: -------------------------------------------------------------------------------- 1 | package com.jzhu.flutterstudy.plugin; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Build; 8 | import android.provider.Settings; 9 | import com.tbruyelle.rxpermissions2.RxPermissions; 10 | import io.flutter.plugin.common.MethodCall; 11 | import io.flutter.plugin.common.MethodChannel; 12 | import io.flutter.plugin.common.PluginRegistry; 13 | import io.reactivex.functions.Consumer; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public class FlutterPluginPermissions implements MethodChannel.MethodCallHandler { 20 | 21 | public static String CHANNEL = "com.jzhu.permisstions/plugin"; 22 | 23 | static MethodChannel channel; 24 | 25 | private Activity activity; 26 | 27 | private HashMap permissionsMap = new HashMap<>(); 28 | 29 | private RxPermissions rxPermissions; 30 | 31 | private FlutterPluginPermissions(Activity activity) { 32 | this.activity = activity; 33 | rxPermissions = new RxPermissions(activity); 34 | initPermissions(); 35 | } 36 | 37 | public static void registerWith(PluginRegistry.Registrar registrar) { 38 | channel = new MethodChannel(registrar.messenger(), CHANNEL); 39 | FlutterPluginPermissions instance = new FlutterPluginPermissions(registrar.activity()); 40 | channel.setMethodCallHandler(instance); 41 | } 42 | 43 | @Override 44 | public void onMethodCall(MethodCall call, final MethodChannel.Result result) { 45 | 46 | if (call.method.equals("askPermissions")) { 47 | 48 | 49 | //如果小于6。0的不需要判断权限 50 | if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M){ 51 | result.success(true); 52 | return; 53 | } 54 | 55 | 56 | List list = (List) call.arguments; 57 | 58 | List permissionslist = new ArrayList<>(); 59 | 60 | for (String per : list) { 61 | permissionslist.add(permissionsMap.get(per)); 62 | } 63 | 64 | String[] permissions = new String[list.size()]; 65 | 66 | permissionslist.toArray(permissions); 67 | 68 | rxPermissions 69 | .request(permissions) 70 | .subscribe(new Consumer() { 71 | @Override 72 | public void accept(Boolean aBoolean) throws Exception { 73 | result.success(aBoolean); 74 | } 75 | }); 76 | 77 | }else if(call.method.equals("openSetting")){ 78 | openSettings(); 79 | } 80 | else { 81 | result.notImplemented(); 82 | } 83 | } 84 | 85 | private void openSettings() { 86 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 87 | Uri.parse("package:" + activity.getPackageName())); 88 | intent.addCategory(Intent.CATEGORY_DEFAULT); 89 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 90 | activity.startActivity(intent); 91 | } 92 | 93 | 94 | /** 95 | * 权限 96 | */ 97 | 98 | private void initPermissions() { 99 | permissionsMap.put("ACCESS_COARSE_LOCATION", Manifest.permission.ACCESS_COARSE_LOCATION); 100 | permissionsMap.put("ACCESS_FINE_LOCATION", Manifest.permission.ACCESS_FINE_LOCATION); 101 | permissionsMap.put("ACCESS_NETWORK_STATE", Manifest.permission.ACCESS_NETWORK_STATE); 102 | permissionsMap.put("Permissions.ACCESS_WIFI_STATE", Manifest.permission.ACCESS_WIFI_STATE); 103 | permissionsMap.put("CHANGE_WIFI_STATE", Manifest.permission.CHANGE_WIFI_STATE); 104 | permissionsMap.put("INTERNET", Manifest.permission.INTERNET); 105 | permissionsMap.put("READ_PHONE_STATE", Manifest.permission.READ_PHONE_STATE); 106 | permissionsMap.put("WRITE_EXTERNAL_STORAGE", Manifest.permission.WRITE_EXTERNAL_STORAGE); 107 | permissionsMap.put("ACCESS_LOCATION_EXTRA_COMMANDS", Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS); 108 | permissionsMap.put("BLUETOOTH", Manifest.permission.BLUETOOTH); 109 | permissionsMap.put("BLUETOOTH_ADMIN", Manifest.permission.BLUETOOTH_ADMIN); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/layout/activity_one.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 |