Skip to content

Commit 35fc5f9

Browse files
committed
添加Flutter Module组件依赖
1 parent ae4cdef commit 35fc5f9

21 files changed

+1071
-4
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@
1111
/build
1212
/captures
1313
.externalNativeBuild
14+
/flutter_module/.android/
15+
/flutter_module/.dart_tool/
16+
/flutter_module/.idea/
17+
/flutter_module/.ios/
18+
/flutter_module/.flutter-plugins
19+
/flutter_module/.flutter-plugins-dependencies
20+
/flutter_module/.packages

Jetpeck_Flutter_Trend

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter_module/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Jetpeck_Flutter_Trend
2+
[Jetpack_Github](https://github.com/fmtjava/Jetpack_GitHub)项目对应的趋势模块Flutter代码工程,项目架构使用了Bloc,不熟悉Bloc的小伙伴,可参考Bloc中文官方网址:https://bloclibrary.dev/#/zh-cn/architecture
3+
4+
## Getting Started
5+
6+
For help getting started with Flutter, view our online
7+
[documentation](https://flutter.dev/).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter_bloc/flutter_bloc.dart';
2+
import 'package:flutter_module/bloc/trend_event.dart';
3+
import 'package:flutter_module/bloc/trend_state.dart';
4+
import 'package:flutter_module/model/trend_model.dart';
5+
import 'package:flutter_module/repository/trend_repository.dart';
6+
7+
class TrendBloc extends Bloc<TrendEvent, TrendState> {
8+
String since = "daily";
9+
10+
TrendBloc(TrendState initialState) : super(initialState);
11+
12+
@override
13+
Stream<TrendState> mapEventToState(TrendEvent event) async* {
14+
if (event is GetTrendEvent) {
15+
since = event.since;
16+
yield LoadingState();
17+
try {
18+
List<TrendModel> trendList =
19+
await TrendRepository.getTrendList(since: since);
20+
yield SuccessState(trendList);
21+
} catch (e) {
22+
yield FailState(e.toString());
23+
}
24+
}
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:equatable/equatable.dart';
2+
3+
abstract class TrendEvent extends Equatable {
4+
@override
5+
List<Object> get props => [];
6+
}
7+
8+
class GetTrendEvent extends TrendEvent {
9+
final String since;
10+
11+
GetTrendEvent({this.since = "daily"});
12+
13+
@override
14+
List<Object> get props => [since];
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:flutter_module/model/trend_model.dart';
3+
4+
abstract class TrendState extends Equatable {
5+
6+
const TrendState();
7+
8+
@override
9+
List<Object> get props => [];
10+
}
11+
12+
class LoadingState extends TrendState {}
13+
14+
class SuccessState extends TrendState {
15+
final List<TrendModel> trendList;
16+
17+
SuccessState(this.trendList);
18+
19+
@override
20+
List<Object> get props => [trendList];
21+
}
22+
23+
class FailState extends TrendState {
24+
final String message;
25+
26+
FailState(this.message);
27+
28+
@override
29+
List<Object> get props => [message];
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
class DColor {
4+
5+
static Color themeColor = Color(0xff25292d);
6+
static Color desTextColor = Color(0xff787878);
7+
static Color startTextColor = Color(0xffC8C8C8);
8+
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:dio/dio.dart';
2+
3+
typedef SuccessCallback = void Function(dynamic data);
4+
typedef ErrorCallback = void Function(String error);
5+
6+
class HttpManager {
7+
HttpManager._();
8+
9+
static BaseOptions _baseOptions =
10+
BaseOptions(headers: {"api-token": "4d65e2a5626103f92a71867d7b49fea0"});
11+
static Dio _dio = Dio(_baseOptions);
12+
13+
static get(String url, SuccessCallback success, ErrorCallback error) async {
14+
try {
15+
Response response = await _dio.get(url);
16+
if (response.statusCode != 200) {
17+
throw Exception(
18+
"statusCode=${response.statusCode},statusMessage=${response.statusMessage}");
19+
} else {
20+
success(response.data);
21+
}
22+
} catch (e) {
23+
error(e.toString());
24+
}
25+
}
26+
27+
static Future request(String url) async {
28+
try {
29+
Response response = await _dio.get(url);
30+
if (response.statusCode != 200) {
31+
throw Exception(
32+
"statusCode=${response.statusCode},statusMessage=${response.statusMessage}");
33+
} else {
34+
return response.data;
35+
}
36+
} catch (e) {
37+
throw Exception(e.toString());
38+
}
39+
}
40+
}

flutter_module/lib/main.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'dart:io';
2+
import 'dart:ui';
3+
4+
import 'package:flutter/material.dart';
5+
import 'package:flutter/services.dart';
6+
import 'package:flutter_module/page/trend_page.dart';
7+
import 'color/color.dart';
8+
9+
void main() {
10+
runApp(MyApp(window.defaultRouteName));
11+
if (Platform.isAndroid) {
12+
// 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。
13+
SystemUiOverlayStyle systemUiOverlayStyle =
14+
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
15+
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
16+
}
17+
}
18+
19+
class MyApp extends StatelessWidget {
20+
final String defaultRoute;
21+
22+
const MyApp(this.defaultRoute, {Key key}) : super(key: key);
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
return MaterialApp(
27+
title: 'GitHub',
28+
theme: ThemeData(
29+
primarySwatch: createMaterialColor(DColor.themeColor),
30+
),
31+
home: _widgetForRoute(defaultRoute));
32+
}
33+
}
34+
35+
Widget _widgetForRoute(String route) {
36+
//根据不同的路由显示不同的界面
37+
switch (route) {
38+
case "trend":
39+
return TrendPage();
40+
default:
41+
return Center(child: Text('Unknown route: $route'));
42+
}
43+
}
44+
45+
//自定义主题颜色
46+
MaterialColor createMaterialColor(Color color) {
47+
List strengths = <double>[.05];
48+
Map swatch = <int, Color>{};
49+
final int r = color.red, g = color.green, b = color.blue;
50+
51+
for (int i = 1; i < 10; i++) {
52+
strengths.add(0.1 * i);
53+
}
54+
strengths.forEach((strength) {
55+
final double ds = 0.5 - strength;
56+
swatch[(strength * 1000).round()] = Color.fromRGBO(
57+
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
58+
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
59+
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
60+
1,
61+
);
62+
});
63+
return MaterialColor(color.value, swatch);
64+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
class TrendModel {
3+
4+
String fullName;
5+
String url;
6+
String description;
7+
String language;
8+
String meta;
9+
List<String> contributors;
10+
String contributorsUrl;
11+
String starCount;
12+
String forkCount;
13+
String name;
14+
String reposName;
15+
16+
TrendModel.fromJsonMap(Map<String, dynamic> map):
17+
fullName = map["fullName"],
18+
url = map["url"],
19+
description = map["description"],
20+
language = map["language"],
21+
meta = map["meta"],
22+
contributors = List<String>.from(map["contributors"]),
23+
contributorsUrl = map["contributorsUrl"],
24+
starCount = map["starCount"],
25+
forkCount = map["forkCount"],
26+
name = map["name"],
27+
reposName = map["reposName"];
28+
29+
Map<String, dynamic> toJson() {
30+
final Map<String, dynamic> data = new Map<String, dynamic>();
31+
data['fullName'] = fullName;
32+
data['url'] = url;
33+
data['description'] = description;
34+
data['language'] = language;
35+
data['meta'] = meta;
36+
data['contributors'] = contributors;
37+
data['contributorsUrl'] = contributorsUrl;
38+
data['starCount'] = starCount;
39+
data['forkCount'] = forkCount;
40+
data['name'] = name;
41+
data['reposName'] = reposName;
42+
return data;
43+
}
44+
}

0 commit comments

Comments
 (0)