小编Kho*_*Phi的帖子

Flutter切换到Tab重新加载小部件并运行FutureBuilder

问题:

我有2个选项卡使用Default Tabs Controller,如下所示:

Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        drawer: Menu(),
        appBar: AppBar(
          title: Container(
            child: Text('Dashboard'),
          ),
          bottom: TabBar(
            tabs: <Widget>[
              Container(
                padding: EdgeInsets.all(8.0),
                child: Text('Deals'),
              ),
              Container(
                padding: EdgeInsets.all(8.0),
                child: Text('Viewer'),
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            DealList(),
            ViewersPage(),
          ],
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

DealList()是一个StatefulWidget像这样建立的:

Widget build(BuildContext context) {
    return FutureBuilder(
      future: this.loadDeals(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        print('Has error: ${snapshot.hasError}');
        print('Has data: ${snapshot.hasData}');
        print('Snapshot …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

无法绑定到'ngOutletContext',因为它不是'ng-template'的已知属性

以下在Angular 4中运行良好

<ng-container *ngFor="let user of list_users">
  <div *ngIf="currentUser.username !== user.username">
    <div class="card">
      bla bla
    </div>
  </div>
</ng-container>
Run Code Online (Sandbox Code Playgroud)

Angular 5抱怨这个错误:

Can't bind to 'ngOutletContext' since it isn't a known property of 'ng-template'.
1. If 'ngOutletContext' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
        <!-- CUSTOM TEMPLATE -->
        <ng-template
            [ERROR ->][ngOutletContext]="{ item: model, index: index }"
            [ngTemplateOutlet]="template">
        "): ng:///TagInputModule/TagComponent.html@12:12
Property binding ngOutletContext …
Run Code Online (Sandbox Code Playgroud)

angular angular5

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

Javascript Mismatch中的PHP Pack/Unpack实现

根据这个问题的相关答案,我试图整理一个类似于这个PHP进程的打包/解包解决方案,但是在Nodejs(Javascript)中使用md5bufferpack

这是PHP方法(改编自DaloRADIUS:

  $challenge = 'c731395aca5dcf45446c0ae83db5319e';
  $uamsecret = 'secret';
  $password = 'password';

  $hexchal = pack ("H32", $challenge);
  $newchal = pack ("H*", md5($hexchal . $uamsecret));
  $response = md5("\0" . $password . $newchal);
  $newpwd = pack("a32", $password);
  $pappassword = implode ("", unpack("H32", ($newpwd ^ $newchal)));

  echo "Response: ---> ", $response, "\n";
  echo "New Password: ---> ", $newpwd, "\n";
  echo "Pap Password: ---> ", $pappassword, "\n";
Run Code Online (Sandbox Code Playgroud)

以上回声如下:

回应PHP

以明文为准:

Response: ---> 2d4bd27184f5eb032641137f728c6043
New Password: ---> password
Pap Password: …
Run Code Online (Sandbox Code Playgroud)

javascript php node.js

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

inlineformset_factory在创建后创建新对象并编辑对象

在django文档中,有一个使用inlineformset_factory来编辑已创建对象的示例

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view

我改变了这个例子:

def manage_books(request):
    author = Author()
    BookInlineFormSet = inlineformset_factory(Author, Book, fields=('title',))
    if request.method == "POST":
        formset = BookInlineFormSet(request.POST, request.FILES, instance=author)
        if formset.is_valid():
            formset.save()
            return HttpResponseRedirect(author.get_absolute_url())
    else:
        formset = BookInlineFormSet(instance=author)
    return render_to_response("manage_books.html", {
        "formset": formset,
    })
Run Code Online (Sandbox Code Playgroud)

使用上面的内容,它只渲染没有父模型的内联模型.

使用inlineformset_factory创建一个新对象,比如作者,与多个图书相关联,这是什么方法?

使用django docs上面的Author Book模型的示例将很有帮助.Django文档仅供例如如何编辑使用inlineformset_factory已经创建的对象,而不是创造新的

django inline-formset

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

使用Firebase重新验证

我将非常感谢有关如何在Firebase中重新验证用户的帮助.如果文档没有解释如何使用它,我想知道添加所有这些强大的功能是否有任何意义:

目前,这正是我正在尝试的,而且它无法正常工作.错误如cannot read property 'credential' of undefined

在构造函数中:

  constructor(@Inject(FirebaseApp) firebaseApp: any) {
    this.auth = firebaseApp.auth();
    console.log(this.auth);
  }
Run Code Online (Sandbox Code Playgroud)

那么功能

changePassword(passwordData) {
    if(passwordData.valid) {
      console.log(passwordData.value);
      // let us reauthenticate first irrespective of how long
      // user's been logged in!

      const user = this.auth.currentUser;
      const credential = this.auth.EmailAuthProvider.credential(user.email, passwordData.value.oldpassword);
      console.log(credential);
      this.auth.reauthenticate(credential)
        .then((_) => {
          console.log('User reauthenticated');
          this.auth.updatePassword(passwordData.value.newpassword)
            .then((_) => {
              console.log('Password changed');
            })
            .catch((error) => {
              console.log(error);
            })
        })
        .catch((error) => {
          console.log(error);
        })
    }
  }
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication angularfire2

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

角度材料Paginator

我会对我的问题非常具体,希望得到一个同样具体的答案.

我已经在线梳理过,关于这个主题Angular文档对于现实生活中的情况都是模糊的,因为要求你从海洋中挑选一根针.Ooh Angular docs ...

到目前为止我做了什么

  <mat-paginator (page)="pageEvent = $event" #paginator [length]="pageLength" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions">
  </mat-paginator>
Run Code Online (Sandbox Code Playgroud)

这在我的组件中

  pageLength: number;
  pageSize: 5;
  pageSizeOptions = [5, 10, 25, 100];
Run Code Online (Sandbox Code Playgroud)

然后我更新pageLength端点响应的时间,如下所示:

  loadRequests() {
    this.busy = true;
    this.request_service.get_requests()
      .subscribe((res) => {
        console.log(res);
        this.requests = res['requests'];
        this.pageLength = this.requests.length; // let's assume length = 1000
      });
  }
Run Code Online (Sandbox Code Playgroud)

上面的渲染在浏览器中很好地呈现了分页的UI

.get_requests()为简单起见,通过消耗的端点仅返回1000个固定项.

现在,这就是我现在正在渲染我的列表的方式:

<mat-card *ngFor="let request of requests">
  <mat-card-title> {{ request.title }}</mat-card-title>
</mat-card>
Run Code Online (Sandbox Code Playgroud)

因此,在上述序言中,我需要完成哪些步骤才能让这个条件符合以下条件:

  • 分页不会继续到端点来为每个pageIndex提取每个项目列表.
  • 在从端点接收到第一次命中的1000个项目之后,分页在客户端本地将这个项目长度分块.没有更多的API调用.

angular

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

Flutter中的守卫

在Angular中,可以使用canActivate进行路线防护。

在Flutter中,该如何处理?守卫在哪里?您如何守护路线?

我在考虑以下方面:

  • 用户登录。他们的令牌存储在“共享首选项”中(正确的令牌存储方式?)
  • 用户关闭了该应用程序。
  • 用户再次打开应用。在应用程序启动时,它将确定用户是否已登录(也许是一种检查令牌存储的服务),然后
  • 如果登录,则加载主页路由
  • 如果未登录,请加载登录页面

dart flutter

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

单击电子邮件验证链接后,user.emailVerified不会更改

学习后,可以在最新的Firebase中发送电子邮件验证,尽管文档丢失了,但我想自己进行测试。

使用以下代码段:

  Auth.$onAuthStateChanged(function(firebaseUser) {
    if (firebaseUser) {
      console.log(firebaseUser);
      if (firebaseUser.emailVerified) {
        // console.log(firebaseUser.emailVerified); 
        toastr.success('Email verified');
      } else {
        toastr.info('Do verify email');
      }
    }
  })
Run Code Online (Sandbox Code Playgroud)

console.log(firebaseUser.emailVerified)返回false,总是,虽然发送的验证已启动,收到的邮件,并点击。

使用电子邮件登录后,我立即检查是否已验证用户,如果未通过验证,则应发送电子邮件:

Auth.$signInWithEmailAndPassword(email, password)
  .then(function(firebaseUser) {
    if (!firebaseUser.emailVerified) {
      firebaseUser.sendEmailVerification();
      console.log('Email verification sent');
    }
    $state.go('home');
  })
Run Code Online (Sandbox Code Playgroud)

在my https://console.firebase.google.com/project/my-app-name/authentication/emails下,默认情况下所有内容均为默认值,其中的验证链接为:

Follow this link to verify your email address. https://my-app-name.firebaseapp.com/__/auth/handler?mode=<action>&oobCode=<code>

我用来注册的电子邮件会收到验证电子邮件,但是,单击链接并不能将更改user.emailVerified为true。

这里概述所有步骤,还是在文档中找不到另一个步骤?

javascript firebase firebase-authentication

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

在刀片模板中使用命名URL

在Django中,我可以这样做:

<a href="{% url 'account_login' %}">Account Link</a>
Run Code Online (Sandbox Code Playgroud)

这将给我domain/account/login在我的urls.py中命名的URL

url(r'^account/login/$', views.Login.as_view(), name='account_login'),
Run Code Online (Sandbox Code Playgroud)

我想在Laravel 5.2中做类似的事情

我目前有这样的事情:

Route::get('/survey/new', ['as' => 'new.survey', 'uses' => 'SurveyController@new_survey']);
Run Code Online (Sandbox Code Playgroud)

如何在模板中使用,以及传入参数?

我偶然发现了这个:https://laravel.com/docs/5.1/helpers,但它只是一个白页,没有关于如何实际使用它的相关内容.

laravel-routing laravel-5

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

类型“List&lt;String&gt;”不是类型转换中“String”类型的子类型

我有这个:

List<String> _filters = <String>[8, 11];

我将其传递_filters到此端点:

this.api.setInterests(token, _filters)
  .then((res) {
    print(res);
  });
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

  Future setInterests(String token, List<String> interests) {
    return _netUtil.post(BASE_URL + "/setinterests", body: {
      "token": token,
      "interests": interests
    }).then((dynamic res) {
      return res;
    });
  }
Run Code Online (Sandbox Code Playgroud)

传递_filters总是抛出错误:

type 'List<String>' is not a subtype of type 'String' in type cast

我不知道 dart 还想从我这里得到什么。

dart flutter

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