小编Erl*_*end的帖子

无法使用计时器,自定义视图和Xamarin关闭AlertDialog

我想使用AlertDialog.Builder创建一个启动画面,一个自定义视图和一个计时器.

我正在使用Xamarin.Android - 我似乎没有'dismiss'方法,我可以称之为'dispose'但是alertDialog视图没有关闭.

示例代码如下:

public class SplashDialog
{
    private readonly AlertDialog.Builder _alert;
    private readonly View _view;


    public SplashDialog(Context context)
    {
        _alert = new AlertDialog.Builder(context);

        var layoutInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
        _view = layoutInflater.Inflate(Resource.Layout.splash, null);
        _alert.SetView(_view);

    }

    public void Show()
    {
        _alert.Show();

      /*
        new Thread(() =>
        {
            Thread.Sleep(3000);
            _view.Dispose();
            _alert.Dispose();

        }).Start();
         * */

        new Handler().PostDelayed(() =>
            {
                _view.Dispose();
                _alert.Dispose();

            }, 3000);
    }
}
Run Code Online (Sandbox Code Playgroud)

splash-screen xamarin.android android-alertdialog xamarin

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

正则表达式匹配具有以哈希开头并以空格结尾的特殊字符的单词

鉴于文本:

This is a #tag and this is another #love@irc.oftc.net and more text.
Run Code Online (Sandbox Code Playgroud)

我想匹配以哈希开头并以空格字符结尾的单词(我不想为 指定特定模式#love@irc.oftc.net)。

我不能使用lookarounds,也不想使用\b.

我试过#.*\b, #.*\s,它会比我要求的更匹配。我猜它*也会匹配空格,所以最后一次检查被忽略。

我使用https://regexr.com/进行测试。

regex special-characters

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

在Flutter中滚动时隐藏键盘

我想隐藏SingleChildScrollView带有焦点的滚动键盘TextFormField。我NotificationListener<ScrollNotification>在的顶部添加SingleChildScrollView,并收听ScrollStartNotification。然后FocusScope.of(context).requestFocus(FocusNode()),我打电话隐藏键盘。

TextFormField位于屏幕底部时,会出现问题。当我单击它并获得焦点时,键盘出现并向上移动SingleChildScrollView,这再次触发ScrollStartNotification并隐藏了键盘。

flutter

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

Dart 中作为可选构造函数参数的列表为 null

在下面的示例中,为什么myList null没有向构造函数传递参数?

我在类中将其声明为空(可增长)列表。

class MyListClass {
  List myList = [];

  MyListClass({this.myList});
}

void main() {
  final obj = MyListClass();
  assert(obj.myList != null);
}
Run Code Online (Sandbox Code Playgroud)

传递可选列表但默认为空列表的最佳方法是什么?

我知道你可以执行以下操作,但也许有更好的方法?

MyListClass({this.myList}) {
  this.myList ??= [];
}
Run Code Online (Sandbox Code Playgroud)

UDATE:这是预期的行为,null如果没有根据this指定值,则这是默认行为。

constructor list dart flutter

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