Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fanngyuan committed Dec 18, 2020
1 parent a88d91e commit c6b77cf
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 28 deletions.
Binary file modified assets/images/starcoin-qr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'package:flutter/material.dart';
import 'package:redux/redux.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:starcoin_node/pages/localizations.dart';
import 'package:starcoin_node/pages/main_page.dart';
import 'package:starcoin_node/style/themes.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'config/states.dart';
import 'pages/routes/page.dart';
Expand Down Expand Up @@ -42,6 +44,17 @@ class App extends StatelessWidget {
child: _buildGlobalLoading(context),
),
new MaterialApp(
localizationsDelegates: [
// 本地化的代理类
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
StarcoinLocalizationsDelegate(),
],
supportedLocales: [
const Locale('en', 'US'), // 美国英语
const Locale('zh', 'CN'), // 中文简体
//其它Locales
],
theme: store.state.theme.themeData,
routes: _buildRoutes(),
home: new MainPage(userName),
Expand Down
8 changes: 6 additions & 2 deletions lib/pages/intro_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:starcoin_node/pages/node_page.dart';
import 'package:starcoin_node/pages/routes/routes.dart';

import 'localizations.dart';

class IntroPage extends StatelessWidget {
static const String routeName = Routes.main + "/intro";

Expand Down Expand Up @@ -38,7 +40,8 @@ class IntroPage extends StatelessWidget {
BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(width: 1, color: blue),
),
hintText: '创建昵称'),
hintText: StarcoinLocalizations.of(context)
.createNickyName),
)),
SizedBox(
height: 20,
Expand All @@ -54,7 +57,8 @@ class IntroPage extends StatelessWidget {
return new NodePage(name);
}));
},
child: const Text('确认', style: TextStyle(fontSize: 30)),
child: Text(StarcoinLocalizations.of(context).confirm,
style: TextStyle(fontSize: 30)),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0),
side: BorderSide(color: blue),
Expand Down
83 changes: 83 additions & 0 deletions lib/pages/localizations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//Locale资源类
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class StarcoinLocalizations {
StarcoinLocalizations(this.isZh);
//是否为中文
bool isZh = false;
//为了使用方便,我们定义一个静态方法
static StarcoinLocalizations of(BuildContext context) {
return Localizations.of<StarcoinLocalizations>(
context, StarcoinLocalizations);
}

//Locale相关值,title为应用标题
String get title {
return isZh ? "Starcoin 挖矿程序" : "Starcoin Miner";
}

String get slogon {
return isZh ? "参与测试网挖矿 瓜分万U!" : "Start Mining Win10K USDT/STC!";
}

String get currentTask {
return isZh ? "当前任务" : "Current Task";
}

String get progress {
return isZh ? "进度" : "Progress";
}

String get balance {
return isZh ? "当前余额" : "Balance";
}

String get minedBlocks {
return isZh ? "已挖块数" : "Mined";
}

String get blockUnit {
return isZh ? "块" : "Blocks";
}

String get currentDiff {
return isZh ? "当前难度" : "Current Difficulty";
}

String get createNickyName {
return isZh ? "创建昵称" : "Create Nicky Name";
}

String get confirm {
return isZh ? "确认" : "Confirm";
}

String get generatePoster {
return isZh ? "生成海报" : "Share Poster";
}

String get offcialWebSite {
return isZh ? "官网" : "Offcial Website";
}
}

class StarcoinLocalizationsDelegate
extends LocalizationsDelegate<StarcoinLocalizations> {
const StarcoinLocalizationsDelegate();

//是否支持某个Local
@override
bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);

// Flutter会调用此类加载相应的Locale资源类
@override
Future<StarcoinLocalizations> load(Locale locale) {
print("$locale");
return SynchronousFuture<StarcoinLocalizations>(
StarcoinLocalizations(locale.languageCode == "zh"));
}

@override
bool shouldReload(StarcoinLocalizationsDelegate old) => false;
}
90 changes: 67 additions & 23 deletions lib/pages/node_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:starcoin_wallet/wallet/node.dart';
import 'dart:io';
import 'dart:convert';
import 'directory_service.dart';
import 'localizations.dart';
import 'routes/routes.dart';
import 'package:date_format/date_format.dart';
import "package:path/path.dart" show join;
Expand Down Expand Up @@ -39,6 +40,9 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
List<String> lines = List();
String address = "0x0fb6d936ddc01ecb151d73d43c545251";

String taskName = "";
String percent = "";

String userName;

GlobalKey previewContainer = new GlobalKey();
Expand Down Expand Up @@ -188,37 +192,65 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
'assets/images/starcoin-miner.png',
width: 50,
),
Text(
"参与测试网挖矿 瓜分万U!",
style: TextStyle(color: Colors.white, fontSize: 20),
),
Column(children: <Widget>[
Text(StarcoinLocalizations.of(context).slogon,
style: TextStyle(
color: Colors.white, fontSize: 15)),
Text(
StarcoinLocalizations.of(context)
.offcialWebSite +
': starcoin.org',
style: TextStyle(color: blue, fontSize: 15)),
]),
Expanded(
flex: 1,
child: Container(
margin: EdgeInsets.only(right: 20),
alignment: Alignment.centerRight,
child: IconButton(
icon: Image.asset(
'assets/images/starcoin-save.png'),
iconSize: 60,
onPressed: () async {
await takescrshot();
},
))),
child: Tooltip(
message: StarcoinLocalizations.of(context)
.generatePoster,
child: IconButton(
icon: Image.asset(
'assets/images/starcoin-save.png'),
iconSize: 60,
onPressed: () async {
await takescrshot();
},
)))),
],
),
Container(
margin: EdgeInsets.only(left: 160, top: 10, right: 150),
alignment: Alignment(0, 0),
child: Center(
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10),
alignment: Alignment.centerRight,
child: Text(
time,
style: TextStyle(color: blue, fontSize: 15),
)),
Row(children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10),
child: Text(
StarcoinLocalizations.of(context)
.currentTask +
":$taskName",
style: TextStyle(color: blue, fontSize: 13),
)),
Container(
margin: EdgeInsets.only(bottom: 10, left: 10),
child: Text(
StarcoinLocalizations.of(context).progress +
":$percent%",
style: TextStyle(color: blue, fontSize: 13),
)),
Expanded(
child: Container(
margin: EdgeInsets.only(bottom: 10),
alignment: Alignment.centerRight,
child: Text(
time,
style:
TextStyle(color: blue, fontSize: 13),
)))
]),
Container(
padding: EdgeInsets.only(
left: 20, right: 20, top: 10, bottom: 10),
Expand Down Expand Up @@ -251,7 +283,7 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
height: iconSize,
),
Text(
"当前余额",
StarcoinLocalizations.of(context).balance,
style: blueTextstyle,
),
Container(
Expand All @@ -272,14 +304,18 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
height: iconSize,
),
Text(
"已挖块数",
StarcoinLocalizations.of(context)
.minedBlocks,
style: blueTextstyle,
),
Container(
padding: edgeTexts,
child: Text("$blocks",
style: whiteTextstyle)),
Text("块", style: blueTextstyle)
Text(
StarcoinLocalizations.of(context)
.blockUnit,
style: blueTextstyle)
],
)),
SizedBox(height: 5),
Expand All @@ -292,7 +328,10 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
width: iconSize,
height: iconSize,
),
Text("当前难度", style: blueTextstyle),
Text(
StarcoinLocalizations.of(context)
.currentDiff,
style: blueTextstyle),
Container(
padding: edgeTexts,
child: Text(difficulty,
Expand Down Expand Up @@ -337,10 +376,15 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
final totalDifficulty =
nodeInfo['peer_info']['chain_info']['total_difficulty'];

final syncProgress = await node.syncProgress();
final taskNames = syncProgress['current']['task_name'].split("::");

setState(() {
this.address = address.toString();
this.balance = balance.toBigInt() / BigInt.from(1000000000);
this.difficulty = totalDifficulty;
this.taskName = taskNames[taskNames.length - 1];
this.percent = syncProgress['current']['percent'].toStringAsFixed(2);
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64-release`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`)
- shared_preferences (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences/macos`)
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)

EXTERNAL SOURCES:
FlutterMacOS:
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64-release
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64
shared_preferences:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences/macos
shared_preferences_macos:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^3.1.0+1
hex: ^0.1.2
shared_preferences: ^0.5.6+1
intl: ^0.16.1
flutter_spinkit: "^4.1.1+1"
flutter_hooks: ^0.9.0
built_value: ^7.1.0
Expand Down

0 comments on commit c6b77cf

Please sign in to comment.