Skip to content

Commit

Permalink
新增简历页
Browse files Browse the repository at this point in the history
  • Loading branch information
OMGVecchio committed Nov 29, 2018
1 parent 8776c90 commit 4c46611
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

## 路由

实现路由跳转有几种方式、优劣,想象下使用场景
实现路由跳转有几种方式、优劣,想象下使用场景。现在路由切换时的渲染处理是否有问题?怎么提升性能
41 changes: 41 additions & 0 deletions lib/components/bottom_nav.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';

class SelfBottomNav extends StatelessWidget {
final int index;
SelfBottomNav({ @required this.index });
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: index,
onTap: (int index) {
switch (index) {
case 1:
Navigator.pushReplacementNamed(context, '/');
// Navigator.pushNamed(context, '/');
break;
case 2:
Navigator.pushReplacementNamed(context, '/cv');
// Navigator.pushNamed(context, '/cv');
break;
default:
Navigator.pushReplacementNamed(context, '/');
// Navigator.pushNamed(context, '/');
}
},
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: new Icon(Icons.book),
title: new Text('Blog'),
),
BottomNavigationBarItem(
icon: new Icon(Icons.image),
title: new Text('没开通'),
),
BottomNavigationBarItem(
icon: new Icon(Icons.work),
title: new Text('CV'),
),
],
);
}
}
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

import 'pages/article_list.dart';
// import 'pages/article_detail.dart';
import 'pages/curriculum_vitae.dart';

void main() => runApp(new MyApp());

Expand All @@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {
),
home: ArticleListPage(),
routes: <String, WidgetBuilder> {
// '/article': (BuildContext ctx) => ArticleDetailPage(),
'/cv': (BuildContext ctx) => CurriculumVitae()
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/article_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ArticleDetailState extends State {
this._fetchArticleDetail();
}
void _fetchArticleDetail() async {
Response res = await dio.get('https://vecchio.top/api/article/${this.articleId}');
// Response res = await dio.get('https://vecchio.top/api/article/f24be360-9bac-11e8-af01-d933a8a0c468');
Response res = await dio.get('${ArticleUtils.host}/api/article/${this.articleId}');
// Response res = await dio.get('${ArticleUtils.host}/api/article/f24be360-9bac-11e8-af01-d933a8a0c468');
setState(() {
articleDetail = res.data['data'];
});
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/article_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

import 'article_detail.dart';
import '../components/bottom_nav.dart';
import '../utils/article_utils.dart';

Dio dio = Dio();
Expand All @@ -13,6 +14,7 @@ class ArticleListPage extends StatelessWidget {
appBar: AppBar(
title: Text('文章列表'),
),
bottomNavigationBar: SelfBottomNav(index: 0),
body: ArticleList(),
);
}
Expand All @@ -29,7 +31,7 @@ class ArticleListState extends State {
this._fetchArticleList();
}
void _fetchArticleList() async {
Response res = await dio.get('https://vecchio.top/api/article');
Response res = await dio.get('${ArticleUtils.host}/api/article');
setState(() {
articleList.addAll(res.data['data']);
});
Expand Down
16 changes: 16 additions & 0 deletions lib/pages/curriculum_vitae.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

import '../components/bottom_nav.dart';

class CurriculumVitae extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('简历'),
),
bottomNavigationBar: SelfBottomNav(index: 2),
body: Text('简历'),
);
}
}
10 changes: 6 additions & 4 deletions lib/utils/article_utils.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const String defaultCoverUrl = 'https://vecchio.top/images/cover/wallhaven-851_1537242430407.jpg';

class ArticleUtils {
static const String host = 'https://vecchio.top';

static const String defaultCoverUrl = '${ArticleUtils.host}/images/cover/wallhaven-851_1537242430407.jpg';

static String getCoverUrl(String coverUrl) {
RegExp exp = RegExp('^(https?:)?//');
String articleCover = coverUrl != null
? exp.hasMatch(coverUrl)
? coverUrl
: 'https://vecchio.top${coverUrl}'
: defaultCoverUrl;
: (ArticleUtils.host + coverUrl)
: ArticleUtils.defaultCoverUrl;
return articleCover;
}
}

0 comments on commit 4c46611

Please sign in to comment.