我在Stackoverflow上搜索了它,但是关于颤动,我没有找到任何相关的解决方案,这里和这里 可能是同一个问题,但它们不是为了颤动.
我正在使用JSON文件并注册Pubspec.ymal
但显示错误,当我使用图像并注册它时,也会发生同样的错误.也许它有一个格式错误,但我不知道它有什么问题.这是我遵循的文档.
pubspec.yaml第29行第29行出错:解析块映射时需要一个键. 资产: ^
这是我的pubspec.yaml
档案
name: jsondata description: A new Flutter application.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- loadjson/person.json
Run Code Online (Sandbox Code Playgroud)
我有一个活动,其中声明了一个接口,并且我有一个ViewModel
已覆盖接口的类,并且想要调用接口的方法Activity
以在ViewModel
类中进行更改,但无法调用方法,Activity
说ViewModel 类没有伴随对象,因此必须在这里初始化。如何解决这个问题?
var selection: setSelectionSubRow? = null
selection=RowSubTShirtViewModel
selection!!.setNameSelection(false)
Run Code Online (Sandbox Code Playgroud)
上面的代码在Activity
其名称中TShirtActivity
。
下面的代码来自RowViewModel
类
class RowSubTShirtViewModel(private val subTShirtAdapter: SubTShirtAdapter, val context: TShirtActivity,
val tShirtBean: CommonItemBean, private val parentPosition: Int, private val position: Int) : BaseObservable() ,TShirtActivity.setSelectionSubRow{
fun getImageDrawable(): Drawable {
return if (tShirtBean.isSelected)
ContextCompat.getDrawable(context, R.drawable.green_border_circle)!!
else
ContextCompat.getDrawable(context, R.drawable.border_circle)!!
}
override fun setNameSelection(selection: Boolean) {
if (parentPosition == 6) {
if (position == 1) {
tShirtBean.isSelected = false …
Run Code Online (Sandbox Code Playgroud) 我需要一个圆角TextField
,我可以这样做,但它显示的是默认边框颜色。我尝试更改borderSide
但无法更改颜色(它仍然是黑色):
TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(
Icons.person,
color: Colors.white,
),
border: OutlineInputBorder(
// width: 0.0 produces a thin "hairline" border
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(color: Colors.white24)
//borderSide: const BorderSide(),
),
hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight"),
filled: true,
fillColor: Colors.white24,
hintText: 'Password'),
),
Run Code Online (Sandbox Code Playgroud)
我需要这个,我不想要焦点线,但光标应该是白色的。我试图更改border
参数中的所有内容,但仍然没有更改。
我想要:
我得到这个:
分隔线没有按照我的需要进行调整,列小部件中的所有内容都无法设置垂直线。
Container(
decoration: BoxDecoration(color: Colors.grey[300]),
child:
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(child: TextFormField(
style: new TextStyle(color: Colors.grey),
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: Icon(Icons.search,color: Colors.grey,size: 30.0,),
hintStyle: TextStyle(color: Colors.grey,fontSize: 18.0),
hintText: 'Search',
),),),
IconButton(onPressed:(){},icon: Image.asset('assets/images/grid.png',fit: BoxFit.contain ,),),
Container(decoration: BoxDecoration(color: Colors.grey),width: 5.0,child: Text(''),),
IconButton(onPressed:(){},icon: Image.asset('assets/images/list.png',fit: BoxFit.contain ,),),
],
)),
Divider(color: Colors.grey,),
Run Code Online (Sandbox Code Playgroud)
得到这个
我想反转列表,我已经通过使用 reverse: true,
. 它正在工作,但是当列表的项目最少时,列表已与底部对齐并在顶部显示空白区域。
Expanded(child: ListView.builder(
shrinkWrap: true,
reverse: true,
controller: _scrollController,
itemCount:order_response.orderDetails.length,
itemBuilder: (context, position) {return orderListItemTile(width,height,order_response,position);},
),)
Run Code Online (Sandbox Code Playgroud)
但是当我删除expanded()
小部件时,当项目增加时,它会按像素溢出。
ListView.builder(
shrinkWrap: true,
reverse: true,
controller: _scrollController,
itemCount:order_response.orderDetails.length,
itemBuilder: (context, position) {return orderListItemTile(width,height,order_response,position);},
),
Run Code Online (Sandbox Code Playgroud)
键盘出现时背景图像挤压。
Scaffold(
body: Stack(
children: <Widget>[
Container(
width:double.infinity ,
height: double.infinity ,
child: Image.asset('assets/images/bg.png')),
Container(
child: SingleChildScrollView(
padding: EdgeInsets.all(width*0.10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(height: height*0.10,),
Container(decoration: BoxDecoration(color:Colors.transparent),child: Container(margin: EdgeInsets.only(bottom: height*0.02,left: 20.0,right: 20.0),child: Image.asset('assets/images/logo.png'),),),
SizedBox(height: height*0.05,),
Container(
decoration: BoxDecoration(color: Colors.transparent),
child: new Form(
key: _formKey,
autovalidate: _autoValidate,
child: LoginFrom(width,height))),
],
),
),
),
],
)
)
Run Code Online (Sandbox Code Playgroud)
我需要使用本地通知在应用程序处于前台时显示Firebase通知,但无法正常工作。
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin=new FlutterLocalNotificationsPlugin();
static FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
static StreamController<Map<String, dynamic>> _onMessageStreamController =
StreamController.broadcast();
static StreamController<Map<String, dynamic>> _streamController =
StreamController.broadcast();
static final Stream<Map<String, dynamic>> onFcmMessage =
_streamController.stream;
@override
void initState() {
super.initState();
var android=AndroidInitializationSettings('mipmap/ic_launcher.png');
var ios=IOSInitializationSettings();
var platform=new InitializationSettings(android,ios);
flutterLocalNotificationsPlugin.initialize(platform);
firebaseCloudMessaging_Listeners();
}
Run Code Online (Sandbox Code Playgroud)
这是Firebase代码
void firebaseCloudMessaging_Listeners() {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token) {
print("FCM TOKEN--" + token);
});
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
showNotification(message);
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: …
Run Code Online (Sandbox Code Playgroud) android push-notification dart flutter firebase-cloud-messaging
我试图仅在容器中在角落制作边框。
Container(
padding: const EdgeInsets.only(right: 8.0, left: 8.0),
height: 60,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
side: BorderSide(color: appThemeColor.shade200, width: 0.5),
borderRadius: BorderRadius.circular(5)),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(15),
bottomRight: Radius.circular(15)),
color: Colors.deepPurple,
),
width: 5,
),
],
),
),
)
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我正在使用WebView进行注册.在注册过程中,我必须从设备上传图像.我已完成此代码,它在除Marshmallow之外的每个Android版本中都能正常运行.我已经从清单中获得了所有必要的权限.
代码:
public class WebViewActivity extends Activity {
private static final int INPUT_FILE_REQUEST_CODE = 1;
private static final int FILECHOOSER_RESULTCODE = 1;
private static final String TAG = WebViewActivity.class.getSimpleName();
private static final int TIME_DELAY = 2000;
private static long back_pressed;
private WebView webView;
private WebSettings webSettings;
private ValueCallback<Uri> mUploadMessage;
private Uri mCapturedImageURI = null;
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (requestCode != INPUT_FILE_REQUEST_CODE || …
Run Code Online (Sandbox Code Playgroud) 我无法从先前可用的问题中找到解决方案,我已将 json
字符串转换为map
下面是我的 API 调用方法。
Future<EventResponse> fetchEvent( ) async { // here i change Future type
String url='http://xxxxxxxxxxxx.tk/api/userapp/event/lists';
var headers = new Map<String, String>();//here i defined Map type
headers['Auth-Key'] = 'OCDOC@2018';
headers['End-Client'] = 'OCDOC';
var body = new Map<String, String>();//here i defined Map type
headers['schedule'] = 'present';
http.Response res = await http.post(url,headers: headers, body: body);
final parsed=json.decode(res.body);
var myMap = Map<String, dynamic>.from(parsed);
EventResponse eventResponse = EventResponse.convertEventResponse(myMap);
return eventResponse;
}
Run Code Online (Sandbox Code Playgroud)
这是我的convertEventResponse
方法
factory EventResponse.convertEventResponse(Map<String, dynamic> json) {
List<dynamic> …
Run Code Online (Sandbox Code Playgroud)