mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-06-07 03:09:38 +08:00
feat(首页欢迎图, 加入第一次访问判断.):
This commit is contained in:
@ -5,9 +5,12 @@ import 'routers/routers.dart';
|
|||||||
import 'routers/application.dart';
|
import 'routers/application.dart';
|
||||||
import 'package:flutter_go/utils/provider.dart';
|
import 'package:flutter_go/utils/provider.dart';
|
||||||
import 'package:flutter_go/utils/shared_preferences.dart';
|
import 'package:flutter_go/utils/shared_preferences.dart';
|
||||||
|
import 'package:flutter_go/views/first_page/home.dart';
|
||||||
import 'views/welcome_page/index.dart';
|
import 'views/welcome_page/index.dart';
|
||||||
|
|
||||||
const int ThemeColor = 0xFFC91B3A;
|
const int ThemeColor = 0xFFC91B3A;
|
||||||
|
SpUtil sp;
|
||||||
|
var db;
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
MyApp() {
|
MyApp() {
|
||||||
@ -15,9 +18,17 @@ class MyApp extends StatelessWidget {
|
|||||||
Routes.configureRoutes(router);
|
Routes.configureRoutes(router);
|
||||||
Application.router = router;
|
Application.router = router;
|
||||||
}
|
}
|
||||||
|
showWelcomePage() {
|
||||||
|
bool showWelcome = sp.getBool(sharedPreferencesKeys.showWelcome);
|
||||||
|
if (showWelcome == null || showWelcome == true) {
|
||||||
|
return WelcomePage();
|
||||||
|
} else {
|
||||||
|
return AppPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
showWelcomePage();
|
||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
title: 'title',
|
title: 'title',
|
||||||
theme: new ThemeData(
|
theme: new ThemeData(
|
||||||
@ -34,19 +45,18 @@ class MyApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
home: new Scaffold(
|
home: new Scaffold(
|
||||||
body: new WelcomePage(),
|
body: showWelcomePage()
|
||||||
),
|
),
|
||||||
onGenerateRoute: Application.router.generator,
|
onGenerateRoute: Application.router.generator,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var db;
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
final provider = new Provider();
|
final provider = new Provider();
|
||||||
await provider.init(true);
|
await provider.init(true);
|
||||||
Application.sharePeferences = await SpUtil.instance;
|
sp = await SpUtil.getInstance();
|
||||||
db = Provider.db;
|
db = Provider.db;
|
||||||
runApp(new MyApp());
|
runApp(new MyApp());
|
||||||
}
|
}
|
||||||
|
@ -7,22 +7,24 @@
|
|||||||
* tartget: xxx
|
* tartget: xxx
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum DateType {
|
//enum DateType {
|
||||||
Int,
|
// Int,
|
||||||
Double,
|
// Double,
|
||||||
Bool,
|
// Bool,
|
||||||
String,
|
// String,
|
||||||
Dynamic
|
// Dynamic
|
||||||
}
|
//}
|
||||||
|
|
||||||
class spKey {
|
//class spKey {
|
||||||
String name;
|
// String name;
|
||||||
DateType type;
|
// DateType type;
|
||||||
|
//
|
||||||
spKey({this.name, this.type});
|
// spKey({this.name, this.type});
|
||||||
}
|
//}
|
||||||
|
|
||||||
class sharedPreferencesKeys {
|
class sharedPreferencesKeys {
|
||||||
static spKey loginWelcome = spKey(name: 'loginWelcone', type: DateType.Bool);
|
/// boolean
|
||||||
|
/// 用于欢迎页面. 只有第一次访问才会显示. 或者手动将这个值设为false
|
||||||
|
static String showWelcome = 'loginWelcone';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
export 'package:flutter_go/resources/shared_preferences_keys.dart';
|
||||||
///
|
///
|
||||||
/// 用来做shared_preferences的存储
|
/// 用来做shared_preferences的存储
|
||||||
class SpUtil {
|
class SpUtil {
|
||||||
static SpUtil _instance;
|
static SpUtil _instance;
|
||||||
static Future<SpUtil> get instance async {
|
static Future<SpUtil> get instance async {
|
||||||
return await _getInstance();
|
return await getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
static SharedPreferences _spf;
|
static SharedPreferences _spf;
|
||||||
@ -19,7 +19,8 @@ class SpUtil {
|
|||||||
_spf = await SharedPreferences.getInstance();
|
_spf = await SharedPreferences.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<SpUtil> _getInstance() async {
|
static Future<SpUtil> getInstance() async {
|
||||||
|
print("_instance>>$_instance");
|
||||||
if (_instance == null) {
|
if (_instance == null) {
|
||||||
_instance = new SpUtil._();
|
_instance = new SpUtil._();
|
||||||
await _instance._init();
|
await _instance._init();
|
||||||
@ -29,83 +30,90 @@ class SpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool _beforCheck() {
|
static bool _beforCheck() {
|
||||||
String a;
|
|
||||||
if (_spf == null) {
|
if (_spf == null) {
|
||||||
return throw new StateError("SharedPreferences must be initialized first, but the insurance is null;");
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 判断是否存在数据
|
||||||
|
bool hasKey(String key) {
|
||||||
|
Set keys = getKeys();
|
||||||
|
return keys.contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Set<String> getKeys() {
|
Set<String> getKeys() {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getKeys();
|
return _spf.getKeys();
|
||||||
}
|
}
|
||||||
dynamic get(String key) {
|
|
||||||
|
get(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getKeys();
|
return _spf.get(key);
|
||||||
}
|
}
|
||||||
static String getString(String key) {
|
|
||||||
|
getString(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getString(key);
|
return _spf.getString(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> putString(String key, String value) {
|
Future<bool> putString(String key, String value) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.setString(key, value);
|
return _spf.setString(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getBool(String key) {
|
bool getBool(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getBool(key);
|
return _spf.getBool(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> putBool(String key, bool value) {
|
Future<bool> putBool(String key, bool value) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.setBool(key, value);
|
return _spf.setBool(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getInt(String key) {
|
int getInt(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getInt(key);
|
return _spf.getInt(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> putInt(String key, int value) {
|
Future<bool> putInt(String key, int value) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.setInt(key, value);
|
return _spf.setInt(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getDouble(String key) {
|
double getDouble(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.getDouble(key);
|
return _spf.getDouble(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> putDouble(String key, double value) {
|
Future<bool> putDouble(String key, double value) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.setDouble(key, value);
|
return _spf.setDouble(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> getStringList(String key) {
|
List<String> getStringList(String key) {
|
||||||
return _spf.getStringList(key);
|
return _spf.getStringList(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> putStringList(String key, List<String> value) {
|
Future<bool> putStringList(String key, List<String> value) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.setStringList(key, value);
|
return _spf.setStringList(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynamic getDynamic(String key) {
|
dynamic getDynamic(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.get(key);
|
return _spf.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static Future<bool> remove(String key) {
|
Future<bool> remove(String key) {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.remove(key);
|
return _spf.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> clear() {
|
Future<bool> clear() {
|
||||||
if (_beforCheck()) return null;
|
if (_beforCheck()) return null;
|
||||||
return _spf.clear();
|
return _spf.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ class FirstPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FirstPageState extends State<FirstPage> with AutomaticKeepAliveClientMixin{
|
class FirstPageState extends State<FirstPage> with AutomaticKeepAliveClientMixin{
|
||||||
Future<SharedPreferences> _prefs=SharedPreferences.getInstance();
|
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||||
Future<bool> _unKnow;
|
Future<bool> _unKnow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../routers/application.dart';
|
import '../../routers/application.dart';
|
||||||
import '../../routers/routers.dart';
|
import '../../routers/routers.dart';
|
||||||
|
import '../../utils/shared_preferences.dart';
|
||||||
|
|
||||||
final pages = [
|
final pages = [
|
||||||
new PageViewModel(
|
new PageViewModel(
|
||||||
@ -30,7 +31,7 @@ final pages = [
|
|||||||
class Page extends StatelessWidget {
|
class Page extends StatelessWidget {
|
||||||
final PageViewModel viewModel;
|
final PageViewModel viewModel;
|
||||||
final double percentVisible;
|
final double percentVisible;
|
||||||
|
SpUtil sp;
|
||||||
Page({
|
Page({
|
||||||
this.viewModel,
|
this.viewModel,
|
||||||
this.percentVisible = 1.0,
|
this.percentVisible = 1.0,
|
||||||
@ -43,8 +44,10 @@ class Page extends StatelessWidget {
|
|||||||
Widget creatButton(
|
Widget creatButton(
|
||||||
BuildContext context, String txt, IconData iconName, String type) {
|
BuildContext context, String txt, IconData iconName, String type) {
|
||||||
return RaisedButton.icon(
|
return RaisedButton.icon(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (type == 'start') {
|
if (type == 'start') {
|
||||||
|
await SpUtil.getInstance()
|
||||||
|
..putBool(sharedPreferencesKeys.showWelcome, false);
|
||||||
_goHomePage(context);
|
_goHomePage(context);
|
||||||
} else if (type == 'goGithub') {
|
} else if (type == 'goGithub') {
|
||||||
Application.router.navigateTo(context,
|
Application.router.navigateTo(context,
|
||||||
|
Reference in New Issue
Block a user