Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d24edad
commit 394c0b5
Showing
229 changed files
with
19,295 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
# tianyue | ||
# 天阅Flutter | ||
|
||
A new Flutter application. | ||
## screen shot | ||
|
||
## Getting Started | ||
<img src="screenshot/android_0.png"> | ||
|
||
This project is a starting point for a Flutter application. | ||
<img src="screenshot/android_1.png"> | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
<img src="screenshot/android_2.png"> | ||
|
||
- [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook) | ||
## Setup | ||
|
||
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. | ||
1. Clone the repo | ||
|
||
2. flutter run | ||
|
||
## Dependency | ||
|
||
* [carousel_slider](https://pub.flutter-io.cn/packages/carousel_slider) | ||
* [cached_network_image](https://pub.flutter-io.cn/packages/cached_network_image) | ||
* [shared_preferences](https://pub.flutter-io.cn/packages/shared_preferences) | ||
* [flutter_webview_plugin](https://pub.flutter-io.cn/packages/flutter_webview_plugin) | ||
* [share](https://pub.flutter-io.cn/packages/share) | ||
|
||
## 简介 | ||
|
||
这是一个用Flutter写的阅读类app。 | ||
|
||
我试着让这个Demo的结构尽量接近实际项目,同时使用比较简单方式去实现功能。这样可以让刚接触Flutter的人更够容易理解代码。 | ||
|
||
App中的网络请求均通过一个名为**Request**的工具类。在Request内部,通过**本地mock**方式,获取模拟数据。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,49 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.zhudong.tianyue"> | ||
|
||
<!-- The INTERNET permission is required for development. Specifically, | ||
<!-- | ||
The INTERNET permission is required for development. Specifically, | ||
flutter needs it to communicate with the running application | ||
to allow setting breakpoints, to provide hot reload, etc. | ||
--> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<!-- | ||
io.flutter.app.FlutterApplication is an android.app.Application that | ||
calls FlutterMain.startInitialization(this); in its onCreate method. | ||
In most cases you can leave this as-is, but you if you want to provide | ||
additional functionality it is fine to subclass or reimplement | ||
FlutterApplication and put your custom class here. --> | ||
FlutterApplication and put your custom class here. | ||
--> | ||
<application | ||
android:name="io.flutter.app.FlutterApplication" | ||
android:label="tianyue" | ||
android:label="天阅" | ||
android:icon="@mipmap/ic_launcher"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
android:theme="@style/LaunchTheme" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" | ||
android:hardwareAccelerated="true" | ||
android:launchMode="singleTop" | ||
android:theme="@style/LaunchTheme" | ||
android:windowSoftInputMode="adjustResize"> | ||
<!-- This keeps the window background of the activity showing | ||
|
||
<!-- | ||
This keeps the window background of the activity showing | ||
until Flutter renders its first frame. It can be removed if | ||
there is no splash screen (such as the default splash screen | ||
defined in @style/LaunchTheme). --> | ||
defined in @style/LaunchTheme). | ||
--> | ||
<meta-data | ||
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" | ||
android:value="true" /> | ||
|
||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".AboutActivity" | ||
android:theme="@style/Theme.AppCompat.NoActionBar"> | ||
</activity> | ||
</application> | ||
</manifest> |
21 changes: 21 additions & 0 deletions
21
android/app/src/main/java/com/zhudong/tianyue/AboutActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.zhudong.tianyue; | ||
|
||
import android.graphics.Color; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
|
||
public class AboutActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_welcome); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
getWindow().setStatusBarColor(Color.parseColor("#ffffff")); | ||
View decor = getWindow().getDecorView(); | ||
decor.setSystemUiVisibility(decor.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | ||
} | ||
} | ||
} |
63 changes: 58 additions & 5 deletions
63
android/app/src/main/java/com/zhudong/tianyue/MainActivity.java
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,66 @@ | ||
package com.zhudong.tianyue; | ||
|
||
import android.os.Bundle; | ||
|
||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
|
||
import android.content.ContextWrapper; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.os.BatteryManager; | ||
import android.os.Build.VERSION; | ||
import android.os.Build.VERSION_CODES; | ||
|
||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
import io.flutter.plugin.common.MethodChannel.Result; | ||
|
||
|
||
public class MainActivity extends FlutterActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
} | ||
private static final String CHANNEL = "samples.flutter.io/battery"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler( | ||
new MethodCallHandler() { | ||
@Override | ||
public void onMethodCall(MethodCall call, Result result) { | ||
if (call.method.equals("getBatteryLevel")) { | ||
int batteryLevel = MainActivity.this.getBatteryLevel(); | ||
|
||
if (batteryLevel != -1) { | ||
result.success(batteryLevel); | ||
} else { | ||
result.error("UNAVAILABLE", "Battery level not available.", null); | ||
} | ||
} else if (call.method.equals("goAboutActivity")) { | ||
Intent intent = new Intent(MainActivity.this, AboutActivity.class); | ||
MainActivity.this.startActivity(intent); | ||
result.success("success"); | ||
} else { | ||
result.notImplemented(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private int getBatteryLevel() { | ||
int batteryLevel; | ||
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { | ||
BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE); | ||
batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); | ||
} else { | ||
Intent intent = new ContextWrapper(getApplicationContext()). | ||
registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); | ||
batteryLevel = (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / | ||
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); | ||
} | ||
|
||
return batteryLevel; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#ffffff" | ||
tools:context=".AboutActivity"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_margin="20dp" | ||
android:lineSpacingExtra="5dp" | ||
android:gravity="center_vertical" | ||
android:textColor="#000000" | ||
android:text="天阅是一款采用flutter编写的阅读app,主要涉及到flutter自定义组件,与原生的通信,跳转原生界面" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Uncomment this line to define a global platform for your project | ||
# platform :ios, '9.0' | ||
|
||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
|
||
project 'Runner', { | ||
'Debug' => :debug, | ||
'Profile' => :release, | ||
'Release' => :release, | ||
} | ||
|
||
def parse_KV_file(file, separator='=') | ||
file_abs_path = File.expand_path(file) | ||
if !File.exists? file_abs_path | ||
return []; | ||
end | ||
pods_ary = [] | ||
skip_line_start_symbols = ["#", "/"] | ||
File.foreach(file_abs_path) { |line| | ||
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } | ||
plugin = line.split(pattern=separator) | ||
if plugin.length == 2 | ||
podname = plugin[0].strip() | ||
path = plugin[1].strip() | ||
podpath = File.expand_path("#{path}", file_abs_path) | ||
pods_ary.push({:name => podname, :path => podpath}); | ||
else | ||
puts "Invalid plugin specification: #{line}" | ||
end | ||
} | ||
return pods_ary | ||
end | ||
|
||
target 'Runner' do | ||
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock | ||
# referring to absolute paths on developers' machines. | ||
system('rm -rf .symlinks') | ||
system('mkdir -p .symlinks/plugins') | ||
|
||
# Flutter Pods | ||
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig') | ||
if generated_xcode_build_settings.empty? | ||
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first." | ||
end | ||
generated_xcode_build_settings.map { |p| | ||
if p[:name] == 'FLUTTER_FRAMEWORK_DIR' | ||
symlink = File.join('.symlinks', 'flutter') | ||
File.symlink(File.dirname(p[:path]), symlink) | ||
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path])) | ||
end | ||
} | ||
|
||
# Plugin Pods | ||
plugin_pods = parse_KV_file('../.flutter-plugins') | ||
plugin_pods.map { |p| | ||
symlink = File.join('.symlinks', 'plugins', p[:name]) | ||
File.symlink(p[:path], symlink) | ||
pod p[:name], :path => File.join(symlink, 'ios') | ||
} | ||
end | ||
|
||
post_install do |installer| | ||
installer.pods_project.targets.each do |target| | ||
target.build_configurations.each do |config| | ||
config.build_settings['ENABLE_BITCODE'] = 'NO' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:tianyue/public.dart'; | ||
|
||
import 'package:tianyue/novel_detail/novel_detail_scene.dart'; | ||
import 'package:tianyue/me/login_scene.dart'; | ||
import 'package:tianyue/me/web_scene.dart'; | ||
import 'package:tianyue/reader/reader_scene.dart'; | ||
|
||
class AppNavigator { | ||
static push(BuildContext context, Widget scene) { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (BuildContext context) => scene, | ||
), | ||
); | ||
} | ||
|
||
static pushNovelDetail(BuildContext context, Novel novel) { | ||
AppNavigator.push(context, NovelDetailScene(novel.id)); | ||
} | ||
|
||
static pushLogin(BuildContext context) { | ||
Navigator.push(context, MaterialPageRoute(builder: (context) { | ||
return LoginScene(); | ||
})); | ||
} | ||
|
||
static pushWeb(BuildContext context, String url, String title) { | ||
Navigator.push(context, MaterialPageRoute(builder: (context) { | ||
return WebScene(url: url, title: title); | ||
})); | ||
} | ||
|
||
static pushReader(BuildContext context, int articleId) { | ||
Navigator.push(context, MaterialPageRoute(builder: (context) { | ||
return ReaderScene(articleId: articleId); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:tianyue/app/splash_scene.dart'; | ||
import 'package:tianyue/public.dart'; | ||
|
||
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>(); | ||
|
||
class AppScene extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'tianyue', | ||
navigatorObservers: [routeObserver], | ||
debugShowCheckedModeBanner: false, | ||
theme: ThemeData( | ||
primaryColor: Colors.white, | ||
dividerColor: Color(0xffeeeeee), | ||
scaffoldBackgroundColor: TYColor.paper, | ||
textTheme: TextTheme(body1: TextStyle(color: TYColor.darkGray)), | ||
), | ||
home: SplashScene(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const String EventToggleTabBarIndex = 'EventToggleTabBarIndex'; |
Oops, something went wrong.