我对共享首选项有一些问题。如何通过关闭应用程序让用户登录?
我已经用这个代码存储了用户名:
setState(() {
preferences.setString('token', dataUser[0]['username']);
Navigator.of(context).pushAndRemoveUntil(
PageTransition(
type: PageTransitionType.rightToLeftWithFade,
child: HomePage()),
(Route<dynamic> route) => false);
});
Run Code Online (Sandbox Code Playgroud)
当我点击按钮登录时,它可以转到主页。为了确保用户名存储/不存储,我使用函数来获取我的令牌并获取该令牌。
我的令牌使用此代码获取我期望的内容:
String checkPref;
getPrefIdUser() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
setState(() {
checkPref = sharedPreferences.getString('token');
if (checkPref == null) {
Navigator.of(context).pushAndRemoveUntil(
PageTransition(
type: PageTransitionType.leftToRightWithFade,
child: LoginPage()),
(Route<dynamic> route) => false);
} else {
// Navigator.of(context).pushAndRemoveUntil(
// PageTransition(
// type: PageTransitionType.leftToRightWithFade,
// child: HomePage()),
// (Route<dynamic> route) => false);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我已经getPrefIdUser()在我的主页中放入了这样的 initState:
@override
void initState() { …Run Code Online (Sandbox Code Playgroud) 我正在使用Stepper Widget 来制作更改 PinCode 表单。一切正常,但我不知道如何禁用之前的步进点击。
例子 :
如果我在第 2 步中单击步进器,我不想返回到第 1 步。
我该如何解决这个问题?
Form(
key: _formKey,
child: Stepper(
steps: steps(),
currentStep: currStep,
onStepContinue: () {
setState(() {
if (formKeys[currStep].currentState.validate()) {
if (currStep < steps().length - 1) {
currStep += 1;
} else if (steps().length == 2) {
print('Done');
} else {
currStep = 0;
}
}
});
},
onStepTapped: (step) {
setState(() {
currStep = step;
print(step);
});
},
),
),
List<Step> …Run Code Online (Sandbox Code Playgroud) 我有模型和虚拟数据来测试这样的:
class TestingLoopingModel {
String id;
int month;
int year;
int value;
TestingLoopingModel({
this.id,
this.month,
this.year,
this.value,
});
}
Run Code Online (Sandbox Code Playgroud)
List<TestingLoopingModel> listTest = [
//TODO Month 12 And 10 is not exist
TestingLoopingModel(
id: DateTime.now().toString(),
month: 2,
year: 2020,
value: 2000,
),
TestingLoopingModel(
id: DateTime.now().toString(),
month: 4,
year: 2020,
value: 1500,
),
TestingLoopingModel(
id: DateTime.now().toString(),
month: 6,
year: 2020,
value: 3000,
),
TestingLoopingModel(
id: DateTime.now().toString(),
month: 8,
year: 2020,
value: 3500,
),
TestingLoopingModel(
id: DateTime.now().toString(),
month: 1,
year: 2020, …Run Code Online (Sandbox Code Playgroud) 我有简单的水平 ListviewBuilder,里面有可以选择的卡片。但问题是,当我选择其中一张卡时,所有卡都被选择。我想要的是我只能选择一张卡,如果我选择另一张卡,删除旧的选择并创建新的选择到新卡。这个怎么做 ?
像这样的东西:
我的失败结果
import 'package:flutter/material.dart';
class IconMenu {
final IconData iconName;
final String titleIcon;
IconMenu({this.iconName, this.titleIcon});
}
List<IconMenu> iconList = [
IconMenu(iconName: Icons.ac_unit, titleIcon: "AC Unit"),
IconMenu(iconName: Icons.access_alarm, titleIcon: "Alarm"),
IconMenu(iconName: Icons.accessibility_new, titleIcon: "accessiblity"),
IconMenu(iconName: Icons.add, titleIcon: "Add"),
];
class TestingScreen extends StatefulWidget {
static const routeName = "/testing-page";
@override
_TestingScreenState createState() => _TestingScreenState();
}
class _TestingScreenState extends State<TestingScreen> {
bool selectedList = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center, …Run Code Online (Sandbox Code Playgroud) 我有通用类来请求名为ReusableRequestServer 的服务器,如果在向服务器发出请求时发生错误,这个类将处理一些异常。
class ReusableRequestServer<T> {
Future<T> requestServer(FutureOr<T> requestServer()) async {
try {
return await requestServer();
} on FormatException catch (_) {
throw ConstText.FORMAT_EXCEPTION;
} on TimeoutException catch (_) {
throw ConstText.TIMEOUT_EXCEPTION;
} on SocketException catch (_) {
throw ConstText.NO_CONNECTION;
} catch (e) {
throw e.toString();
}
}
}
final reusableRequestServer = ReusableRequestServer();
Run Code Online (Sandbox Code Playgroud)
我有一个简单的get请求从服务器获取版本移动,我也实现了ReusableRequestServer。
class MobileVersionApi {
Future<List<MobileVersionModel>> getNewestMobileVersion() async {
var result = await reusableRequestServer.requestServer(() async {
final response = await http …Run Code Online (Sandbox Code Playgroud) 
我有像上面这样的设计,在该设计中我实现了应用程序。我在容器内有 Stack Widget,然后在 Stack 小部件内有 ListviewBuilder ,滚动方向为水平。但问题是,我无法在 Stack 小部件内水平滚动 ListViewBuilder。我该如何解决这个问题?
我的试用失败
class HomeScreen extends StatelessWidget {
static const routeName = "/home-screen";
@override
Widget build(BuildContext context) {
final mqHeight = MediaQuery.of(context).size.height;
final mqWidth = MediaQuery.of(context).size.width;
return SafeArea(
child: Scaffold(
appBar: AppBar(
elevation: 0,
title: Text('Good Morning'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () => "",
)
],
),
body: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
color: Colors.blue,
height: mqHeight / 3,
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Container( …Run Code Online (Sandbox Code Playgroud)