小编Raj*_*eep的帖子

聆听颤动的可变变化

我正在尝试侦听变量更改以执行一些代码。所以变量是一个名为reset. 一旦动画结束或按下按钮(来自另一个小部件),我想执行一些操作(比如重置动画控制器)。在动画结束时执行某事,因为一旦结束AnimationStatus.dismissed将成为它的状态,并且将调用侦听器。然后,这允许我使用回调函数onCountdownexpire来相应地设置变量reset,并根据设置的内容执行if(widget.reset)块中的一些代码。所以没有必要听这个案子。

问题:

但是,假设按下了一个按钮(在另一个小部件中)并且我将变量设置reset为 true。我希望动画停止并重置。我现在不能依赖AnimationStatus监听器,因为它只状态改变执行。我希望它在其状态期间重置。所以我必须以某种方式听变量widget.reset

我对此进行了一些研究,并发现这ValueNotifier可能是一种方法,但关于如何使用它的示例并不多。比如我怎么去听它?

代码:

class Countdown extends StatefulWidget {

  final VoidCallback onCountdownExpire;
  bool reset;
  Countdown(this.onCountdownExpire);

  @override
  CountdownState createState() => CountdownState();
}

class CountdownState extends State<Countdown> with TickerProviderStateMixin {
  AnimationController controller;

  String get timerString {
    Duration duration = controller.duration * controller.value;
    return '${duration.inMinutes}:${(duration.inSeconds % 60).toString()}';
  }

  @override
  void initState() {
    super.initState();
    controller = AnimationController(
      vsync: this, …
Run Code Online (Sandbox Code Playgroud)

dart flutter

21
推荐指数
1
解决办法
2万
查看次数

如何使下拉按钮创建的列表形状呈圆形?

我有一个下拉按钮,它有圆形边缘。现在,如何使单击下拉列表时弹出的列表也具有圆形边缘?

下拉图片:

在此处输入图片说明

单击下拉菜单时弹出的列表图像(我想让这些边缘像我的下拉按钮一样变圆):

在此处输入图片说明

我的代码:

return Theme(
  data: ThemeData(canvasColor: cardBlueColor, brightness: Brightness.dark),
  child:Container(
    width:MediaQuery.of(context).size.width/1.25,
    child:Card(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
      color: cardBlueColor,
      elevation: 8.0,
      child:DropdownButtonHideUnderline(
        child: ButtonTheme(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
          alignedDropdown: true,
          child: DropdownButton(
            elevation: 8,
            icon: Icon(Icons.keyboard_arrow_down),
            value: _dateSelected,
            hint: AutoSizeText(NA_FLIGHT_PAGE_DROPDOWN, style: TextStyle(color: white,),textAlign: TextAlign.center,),
            isDense: false,
            onChanged: (String newValue){
              setState(() {
                _dateSelected = newValue;
                dropdownMap = _getDropdownMap(snapshot);     
              });
            },
            items: dropdownList.map((key){
              return DropdownMenuItem<String>(
                value: key.toString(),
                child: AutoSizeText(key.toString(), style: TextStyle(color: white,),textAlign: TextAlign.center,),
              );
            }).toList(),
          ),
        ),
      )
    )
  )
); …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout

10
推荐指数
2
解决办法
2272
查看次数

如何将我的 Stack Overflow 声誉添加为 GitHub 上的实时徽章?

我正在尝试将我的 Stack Overflow 声誉作为实时徽章添加到我的 GitHub 个人资料自述文件中。

首先,我需要使用一些 API 从 Stack Overflow 以某种方式获取我的帐户信息。接下来,我需要提取声誉,然后将其传递给另一个在 Markdown 中创建徽章的 API。

现在,我做了一些研究,似乎我可以使用 Stack Exchange API通过端点 URL 以 JSON 格式获取我的 Stack Overflow 帐户信息。此外,Shield.io 的API将允许我从完美的端点 URL 创建徽章。但是,Shields.io 要求端点采用特定的 JSON 格式。

所以现在要解决这个难题,我需要第三个 API,它能够从 Stack Exchange API 读取和解析 JSON,然后以所需的 JSON 格式托管端点 URL。RunKit 的API似乎能够做到这一点。

我试图实现的一个例子(但不是提交,而是我的 Stack Overflow 声誉):

在此处输入图片说明

markdown github badge node.js shields.io

10
推荐指数
5
解决办法
571
查看次数

如何在 DropdownButton 中居中文本?

我试图让DropdownButton提示、文本和菜单项出现在中心而不是左边,但TextAlign.center似乎没有做任何事情。

带有提示的下拉图像:

在此处输入图片说明

带有所选项目的下拉列表图像作为文本:

在此处输入图片说明

按下箭头时菜单项的图像:

在此处输入图片说明

我的代码:

return Theme(
  data: ThemeData(canvasColor: blackTrans2, brightness: Brightness.dark),
  child:Container(
    width: MediaQuery.of(context).size.width/1.2,
    decoration: BoxDecoration(
    color: blackTrans,
    borderRadius: BorderRadius.all(Radius.circular(5.0)),
    ),   
    child:DropdownButtonHideUnderline(
      child: ButtonTheme(
        alignedDropdown: true,
        child: DropdownButton(
          value: _dateSelected,
          hint: AutoSizeText(NA_FLIGHT_PAGE_DROPDOWN, style: TextStyle(color: white,),textAlign: TextAlign.center,),
          isDense: false,
          onChanged: (String newValue){
            setState(() {
            _dateSelected = newValue;
            });
          },
          items: snapshot.data.documents.map((DocumentSnapshot document){
            return DropdownMenuItem<String>(
              value: document.documentID,
              child: AutoSizeText(document.documentID, style: TextStyle(color: white,),textAlign: TextAlign.center,),
            );
          }).toList(),
        ),
      ),
    )
  )
);
Run Code Online (Sandbox Code Playgroud)

不确定这是否会影响任何事情,但我正在使用AutoSizeText来动态调整文本大小。

更新:我设法通过使用使菜单项出现在中心Center,但即使使用 …

dart flutter flutter-layout

9
推荐指数
2
解决办法
4337
查看次数

如何让 SingleChildScrollView 从底部开始?

我正在开发一个应用程序并遇到了 SingleChildScrollView 从顶部开始的问题:

在此处输入图片说明

我如何让它像这样从底部开始:

在此处输入图片说明

滚动视图是在topContent屏幕的上半部分实现的:

    final topContent = Stack(
      children: <Widget>[
        Container(
            padding: EdgeInsets.only(left: 10.0),
            height: MediaQuery.of(context).size.height * 0.5,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new AssetImage("assets/images/drones1.jpg"),
                fit: BoxFit.cover,
              ),
            )),
        Container(
          height: MediaQuery.of(context).size.height * 0.5,
          padding: EdgeInsets.all(40.0),
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
          child: SingleChildScrollView(      //scroll view implemented here 
            child: Center(
              child: topContentText,
            ),
          ),
        ),
        Positioned(
          left: 8.0,
          top: 60.0,
          child: InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Icon(Icons.arrow_back, color: Colors.white),
          ),
        ) …
Run Code Online (Sandbox Code Playgroud)

dart flutter

7
推荐指数
2
解决办法
8266
查看次数

颤动底部被无穷大像素溢出

我正面临这个问题,当我将某个小部件添加到列的子项中时,我不断收到“无限像素溢出的底部”。现在这是添加名为 的新小部件之前的样子countdown

在此处输入图片说明

以下是我添加后发生的情况countdown

在此处输入图片说明

这是屏幕下半部分的代码,我在其中添加countdown

    final countdown = Countdown();

    final quizBottomContent = SingleChildScrollView(
      child: Container(
      width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[quizBottomContentText, quizOptions, countdown],
        ),
      )
    ); 

Run Code Online (Sandbox Code Playgroud)

这是倒计时小部件:

import 'package:flutter/material.dart';
import 'dart:math' as math;

class Countdown extends StatefulWidget {
  @override
  CountdownState createState() => CountdownState();
}

class CountdownState extends State<Countdown> with TickerProviderStateMixin {
  AnimationController controller;

  String get timerString {
    Duration duration = controller.duration * controller.value;
    return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
  }

  @override
  void initState() { …
Run Code Online (Sandbox Code Playgroud)

dart flutter

5
推荐指数
1
解决办法
1万
查看次数

导入 com.google.android.gms.auth.api.Auth 的未解析参考

我正在学习如何使用 Google 登录选项开发应用程序,我正在学习本教程。但是,我的活动并没有在导入时注册import com.google.android.gms.auth.api.Auth并且颜色Auth为红色。

package nus.is3261.kotlinapp

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_google_signin.*
import com.google.android.gms.auth.api.Auth
import com.google.android.gms.common.api.GoogleApiClient
import com.google.firebase.auth.FirebaseAuth
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.ConnectionResult
import com.google.firebase.auth.FirebaseUser
import android.content.Intent
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.firebase.auth.GoogleAuthProvider

class GoogleSigninActivity : AppCompatActivity(), View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {

    private val TAG = "JSAGoogleSignIn"
    private val REQUEST_CODE_SIGN_IN = 1234
    private val WEB_CLIENT_ID = "xxxxxx.apps.googleusercontent.com"

    private var mAuth: FirebaseAuth? = null

    private var mGoogleApiClient: GoogleApiClient? = null

    override fun onCreate(savedInstanceState: Bundle?) …
Run Code Online (Sandbox Code Playgroud)

android kotlin firebase android-studio

3
推荐指数
1
解决办法
4642
查看次数

在哪里可以找到 OAuth2.0 的标识符和秘密以及“虚函数”是什么意思?

我正在按照此文档在我的 flutter 应用程序中实现 OAuth2.0 并且不明白一些事情,这是文档中的代码:

import 'dart:io';
import 'package:oauth2/oauth2.dart' as oauth2;

// These URLs are endpoints that are provided by the authorization
// server. They're usually included in the server's documentation of its
// OAuth2 API.
final authorizationEndpoint =
    Uri.parse("http://example.com/oauth2/authorization");
final tokenEndpoint =
    Uri.parse("http://example.com/oauth2/token");

// The authorization server will issue each client a separate client
// identifier and secret, which allows the server to tell which client
// is accessing it. Some servers may also have an anonymous …
Run Code Online (Sandbox Code Playgroud)

android oauth-2.0 dart flutter

3
推荐指数
1
解决办法
1258
查看次数

为什么我不能从 AsyncTask 访问全局变量?

我正在尝试一些东西并偶然发现了一个问题,我无法str1从 class访问全局变量MyAsyncTask。我猜,它一定是一些声明错误,但我不太确定违反了什么。

class MainActivity : AppCompatActivity() {
    var str1 = "0"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        for (i in 0..5){
            val myAsyncTask = MyAsyncTask(this@MainActivity)
            myAsyncTask.execute("-")
            str1 = str1 + "1"
        }

    }
    class MyAsyncTask(private var c : Context):AsyncTask<String,Void,String>(){

        override fun doInBackground(vararg str: String?): String {
            str1 = str1 + str[0] + "2" // str1 is bolded in red, somehow, i cant access it
            return str1
        }

        override fun onPostExecute(result: String?) {
            super.onPostExecute(result)
            Toast.makeText(c, result, …
Run Code Online (Sandbox Code Playgroud)

android android-asynctask kotlin

2
推荐指数
1
解决办法
1162
查看次数

在 flutter 中将小部件动态添加到列的子项

我正在创建一个测验应用程序,需要根据特定问题的选项数量动态显示 mcq 选项。

例如:

在此处输入图片说明

现在按钮的代码在这里:

    final quizOptions = Container(
      width: MediaQuery.of(context).size.width,
      child: Center(
        child: Column(
          children: <Widget>[
            SimpleRoundButton(
                backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
                buttonText: Text(questions[questionNum].options[0], 
                    style: TextStyle(
                        color: Colors.white
                    ),
                ),
                textColor: Colors.white,
                onPressed: (){},
            ),
            SimpleRoundButton(
                backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
                buttonText: Text(questions[questionNum].options[1], 
                    style: TextStyle(
                        color: Colors.white
                    ),
                ),
                textColor: Colors.white,
                onPressed: (){},
            ),
          ],
        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)

如您所见,我能做的是“修复”2 个按钮。有没有办法根据该特定问题的选项数量动态添加按钮?

我有一个名为的列表questions,它是一个问题列表(这是一个类):

class Question {
  String title;
  List options;
  String imagePath;

  Question(
      {this.title, this.options, this.imagePath,});
}


//Example:
Question( …
Run Code Online (Sandbox Code Playgroud)

dart flutter

2
推荐指数
1
解决办法
4469
查看次数

如何更改 CheckboxListTile 的刻度颜色

我已设置好复选框小部件,并希望在选中时将刻度线颜色更改为绿色(当前为白色)。因此,我设法通过添加主题将复选框未选中时的颜色更改为白色。我想将选定的刻度颜色更改为绿色,但是我似乎无法在主题下找到正确的选项来这样做。

代码:

  Widget buildResultTile(data) {
    return Theme(
      data: ThemeData(unselectedWidgetColor: white),
      child:
        CheckboxListTile(
        activeColor: transparent,
        title: AutoSizeText(
          data,
          maxLines: 1,
          style: TextStyle(
            color: white,
          ),
        ),
        value: _serachSelectList.contains(data),
        onChanged: (bool value) {
          setState(() {
            if (value) {
              _serachSelectList.add(data);
            } else {
              _serachSelectList.remove(data);
            }
          });
        },
        secondary: const Icon(Icons.account_box, color: white),      
      )
    );
  } 
Run Code Online (Sandbox Code Playgroud)

未选中:

在此处输入图片说明

选择(我想蜱是Colors.green):

在此处输入图片说明

dart flutter

2
推荐指数
2
解决办法
4808
查看次数