Skip to content

Commit

Permalink
Merge pull request #1 from OMGVecchio/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
OMGVecchio authored Dec 10, 2018
2 parents 0591936 + 06e7ebf commit d43467d
Show file tree
Hide file tree
Showing 14 changed files with 641 additions and 110 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# my_blog

A new Flutter project.
## 组件

## Getting Started
深层次理解 Flutter 的 Widget,了解各个模型、渲染原理,不要再出现宽高超长但一脸懵逼的情况

For help getting started with Flutter, view our online
[documentation](https://flutter.io/).
## 布局

布局组件看似简单,但在实际操作中如不熟悉的概念的话,很容易遇到阻碍,需要熟悉各个布局的知识点、使用场景

### [可滚动的 Widget](https://flutterchina.club/widgets/scrolling/)

## 路由

实现路由跳转有几种方式、优劣,想象下使用场景。现在路由切换时的渲染处理是否有问题?怎么提升性能
Binary file added assets/images/cats.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/octocat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/one_piece_poster.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
</dict>
</plist>
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 @@
// 已废弃,此组件要单独加在每个 Page 下,会在切换页面时重新渲染底部 Tabbar,体验不友好
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, '/');
break;
case 2:
Navigator.pushReplacementNamed(context, '/cv');
break;
default:
Navigator.pushReplacementNamed(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'),
),
],
);
}
}
107 changes: 4 additions & 103 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,111 +1,12 @@
import 'package:flutter/material.dart';

void main() => runApp(MyApp());
import 'pages/page_entry.dart';

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
return PageEntry();
}
}
103 changes: 103 additions & 0 deletions lib/pages/article/article_detail.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
// import 'package:flutter_markdown/flutter_markdown.dart';

import '../../utils/article_utils.dart';

Dio dio = Dio();

class ArticleDetailPage extends StatelessWidget {
final articleId;

ArticleDetailPage(this.articleId);

@override
Widget build(BuildContext context) {
return ArticleDetail(this.articleId);
}
}

class ArticleDetail extends StatefulWidget {
final articleId;

ArticleDetail(this.articleId);

@override
createState() => ArticleDetailState(this.articleId);
}

class ArticleDetailState extends State {
final articleId;
Map articleDetail;

ArticleDetailState(this.articleId) {
this._fetchArticleDetail();
}

void _fetchArticleDetail() async {
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'];
});
}

@override
Widget build(BuildContext context) {
if (articleDetail == null) {
return Center(
child: CircularProgressIndicator(),
);
}
return Scaffold(
appBar: AppBar(
title: Text(articleDetail['title']),
),
body: Container(
child: Column(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Image.network(ArticleUtils.getCoverUrl(articleDetail['cover'])),
Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Container(
child: Row(
textDirection: TextDirection.rtl,
children: <Widget>[
Text(DateTime.fromMillisecondsSinceEpoch(articleDetail['createTime']).toString()),
],
),
),
Container(
margin: EdgeInsets.fromLTRB(0, 8.0, 0, 20.0),
decoration: BoxDecoration(color: Colors.pink[200]),
child: Row(
children: <Widget>[
Text(
articleDetail['desc'],
style: TextStyle(
color: Colors.white,
),
),
],
),
),
Text(articleDetail['article'].toString()),
],
),
),
],
),
),
),
],
),
),
);
}
}
Loading

0 comments on commit d43467d

Please sign in to comment.