Skip to content

Commit

Permalink
Some little mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
CasterKKK committed Dec 12, 2018
1 parent e6fe45d commit a0c5fd9
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 138 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 27

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.ra.flutterrealworldapp"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
21 changes: 11 additions & 10 deletions lib/components/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'package:flutter_realworld_app/generated/i18n.dart';
import 'package:flutter_realworld_app/models/app_state.dart';
import 'package:flutter_realworld_app/models/profile.dart';
import 'package:flutter_realworld_app/models/user.dart';
import 'package:flutter_realworld_app/pages/main_page.dart';
import 'package:flutter_realworld_app/pages/profile_page.dart';
import 'package:flutter_realworld_app/util.dart' as util;
import 'package:flutter_redurx/flutter_redurx.dart';

class AppDrawer extends StatelessWidget {
final AuthUser _currentUser;
final Profile _profile;
Expand Down Expand Up @@ -69,9 +69,10 @@ class AppDrawer extends StatelessWidget {
accountName: Text(_currentUser.username),
accountEmail: Text(_currentUser.email),
currentAccountPicture: CircleAvatar(
backgroundImage: util.isNullEmpty(_currentUser.image, trim: true)
? AssetImage('res/assets/smiley-cyrus.jpg')
: CachedNetworkImageProvider(_currentUser.image),
backgroundImage:
util.isNullEmpty(_currentUser.image, trim: true)
? AssetImage('res/assets/smiley-cyrus.jpg')
: CachedNetworkImageProvider(_currentUser.image),
),
),
),
Expand All @@ -94,13 +95,13 @@ class AppDrawer extends StatelessWidget {
ListTile(
leading: Icon(Icons.power_settings_new),
onTap: () {
Provider.dispatch<AppState>(context, Logout(successCallback: () {
Navigator.of(context).popUntil(ModalRoute.withName("/main"));
Provider.dispatch<AppState>(context,
Logout(successCallback: () {
Navigator.of(context)
.popUntil(ModalRoute.withName("/main"));
Flushbar()
..title =
S.of(context).logoutSuccessfulTitle
..message =
S.of(context).logoutSuccessful
..title = S.of(context).logoutSuccessfulTitle
..message = S.of(context).logoutSuccessful
..duration = Duration(seconds: 5)
..show(context);
}));
Expand Down
40 changes: 17 additions & 23 deletions lib/components/article_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,20 @@ class ArticleItem extends StatefulWidget {
}

class _ArticleItemState extends State<ArticleItem> {
bool _favorited;
int _favoritesCount;
final Article _article;
Article _article;
var dateFormatter = DateFormat('yyyy-mm-dd HH:MM:ss');

_ArticleItemState(this._article) {
this._favorited = this._article.favorited;
this._favoritesCount = this._article.favoritesCount;
}
_ArticleItemState(this._article);

_header(BuildContext context) => Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 4.0),
child: CircleAvatar(
backgroundImage: util.isNullEmpty(_article.author.image, trim: true)
? AssetImage('res/assets/smiley-cyrus.jpg')
: CachedNetworkImageProvider(_article.author.image),
backgroundImage:
util.isNullEmpty(_article.author.image, trim: true)
? AssetImage('res/assets/smiley-cyrus.jpg')
: CachedNetworkImageProvider(_article.author.image),
),
),
Expanded(
Expand All @@ -51,27 +47,25 @@ class _ArticleItemState extends State<ArticleItem> {
onPressed: () async {
try {
final api = await Api.getInstance();
if (_favorited) {
await api.articleUnfavorite(_article.slug);
setState(() {
_favorited = !_favorited;
_favoritesCount--;
});
Article article;
if (_article.favorited) {
article = await api.articleUnfavorite(_article.slug);
} else {
await api.articleFavorite(_article.slug);
setState(() {
_favorited = !_favorited;
_favoritesCount++;
});
article = await api.articleFavorite(_article.slug);
}
setState(() {
this._article = article;
});
} catch (e) {
util.errorHandle(e, context);
}
},
child: Row(
children: <Widget>[
_favorited ? Icon(Icons.favorite) : Icon(Icons.favorite_border),
Text(_favoritesCount.toString())
_article.favorited
? Icon(Icons.favorite)
: Icon(Icons.favorite_border),
Text(_article.favoritesCount.toString())
],
),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class zh_CN extends S {
@override
String get avatarUrl => "头像 URL";
@override
String get logoutSuccessful => "登出成功,将跳转到主界面";
@override
String get mainPageTitle => "主页";
@override
String get bottomNavYours => "你的";
Expand All @@ -142,6 +144,8 @@ class zh_CN extends S {
@override
String get biography => "自我介绍";
@override
String get logoutSuccessfulTitle => "登出成功!";
@override
String get follow => "关注";
@override
String get registerSuccessful => "注册成功,将跳转到登录界面";
Expand Down
5 changes: 2 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_realworld_app/generated/i18n.dart';
import 'package:flutter_realworld_app/models/app_state.dart';
import 'package:flutter_realworld_app/pages/login_page.dart';
import 'package:flutter_realworld_app/pages/main_page.dart';
import 'package:flutter_realworld_app/pages/profile_page.dart';
import 'package:flutter_realworld_app/pages/register_page.dart';
import 'package:flutter_realworld_app/pages/setting_page.dart';
import 'package:flutter_redurx/flutter_redurx.dart';
Expand All @@ -22,8 +21,8 @@ class RealworldApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/main' : (context) => MainPage(),
'/login' : (context) => LoginPage(),
'/main': (context) => MainPage(),
'/login': (context) => LoginPage(),
'/register': (context) => RegisterPage(),
'/setting': (context) => SettingPage()
},
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _LoginPageState extends State<LoginPage> {
keyboardType: TextInputType.emailAddress,
autofocus: false,
decoration: InputDecoration(
hintText: 'Email',
hintText: S.of(context).email,
hintStyle: TextStyle(color: Colors.black45),
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(
Expand All @@ -48,7 +48,7 @@ class _LoginPageState extends State<LoginPage> {
autofocus: false,
obscureText: true,
decoration: InputDecoration(
hintText: 'Password',
hintText: S.of(context).password,
hintStyle: TextStyle(color: Colors.black45),
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(
Expand Down Expand Up @@ -88,7 +88,8 @@ class _LoginPageState extends State<LoginPage> {
context,
AuthLogin(_email, _password, successCallback: () {
util.finishLoading(context);
Navigator.pushNamedAndRemoveUntil(context, '/main', (route) => route == null);
Navigator.pushNamedAndRemoveUntil(
context, '/main', (route) => route == null);
Flushbar()
..title = S.of(context).loginSuccessfulTitle
..message = S.of(context).loginSuccessful
Expand Down
Loading

0 comments on commit a0c5fd9

Please sign in to comment.