小编Car*_*ein的帖子

在 Flutter 中请求位置时,BLoC 不会产生状态

我使用三个 Flutter 包来实现一个功能,用户可以通过拉动刷新,使用 BLoC 逻辑检索地理坐标并将其传递回 Flutter。

  1. 拉动刷新
  2. 集团
  3. 地理定位器

问题是,当我在pull-to-refresh 中发送调用时,我无法让 BLoC 产生返回结果。

geolocation_bloc.dart

class GeolocationBloc extends Bloc<GeolocationEvent, GeolocationState> {
  @override
  GeolocationState get initialState => GeolocationUninitialized();

  @override
  Stream<GeolocationState> mapEventToState(GeolocationEvent event) async* {
    if (event is RequestLocation) {
      yield* _mapGeolocationRequestLocation();
    }
  }

  Stream<GeolocationState> _mapGeolocationRequestLocation() async* {
    Position position;
    position = await Geolocator().getCurrentPosition();
    print("RETRIEVED LOCATION"); // I CAN REACH HERE EVERYTIME.
    if (position == null) {
      yield LocationLoaded(0, 0);
    } else {
      yield LocationLoaded(position.latitude, position.longitude);
    }
}
Run Code Online (Sandbox Code Playgroud)

检索地理坐标。如果传感器关闭/损坏,则返回 (0,0)。

feed_pa​​ge.dart …

dart flutter

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

在 Flutter 中将多个小部件连续扩展到全宽?

我试图在 Flutter 中获取一个按钮以扩展到其父宽度并随着添加更多小部件而动态扩展。例如,如果一行中有两个按钮,它们将每个扩展到 50% 的宽度,三个按钮扩展到 33% 等。

我试过width: Double.infinite哪个适用于单个按钮。可以理解,这不适用于多个按钮,因为宽度不受限制,而且 Flutter 不知道如何调整元素的大小。

我尝试了各种属性,SizedBox, crossAxisAlignmentExpanded但它们似乎不起作用。

我想要实现的目标类似于:https : //bulma.io/documentation/columns/basics/ - 基于 flex 的列布局。

应用程序.dart

class App extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      // theme: WhisperyTheme,
      // theme: ThemeData(fontFamily: "Overpass"),
      home: Scaffold(
        body: Center(
          child: Column(
            children: <Widget>[
              LongButton(
                onTap: () => null,
                text: "Primary Button",
              ),
              Row(
                children: <Widget>[
                  LongButton(
                    onTap: () => null,
                    text: "Secondary Button",
                  ),
                  LongButton(
                    onTap: () => …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

在 gatsby 构建期间无法读取样式组件的主题属性

我正在尝试在 Gatsby 中构建一个使用样式组件设计的网站。

运行gatsby develop显示页面正常,但当我尝试构建页面时,出现以下错误:

错误

Building static HTML failed for path "/Page/"

See our docs page for more info on this error: https://gatsby.dev/debug-html


  16 |     font-family: Lack;
  17 |     text-align: center;
> 18 |     background: ${(props) => props.theme.colors.purple};
     |                                                 ^
  19 |     color: ${(props) => props.theme.colors.white};
  20 |   }
  21 | `;


  WebpackError: TypeError: Cannot read property 'purple' of undefined
Run Code Online (Sandbox Code Playgroud)

布局.jsx

import React from 'react';
import { ThemeProvider, createGlobalStyle } from 'styled-components';
import theme from '../theme/theme';

const …
Run Code Online (Sandbox Code Playgroud)

gatsby styled-components

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

使用java中的Collectors从两个哈希映射返回平均值

我有两个哈希图:busStopsbusServices.

两者在多对多关系中彼此链接,即一个公共汽车站可以有许多服务,一个服务可以有许多公共汽车站.

Hashmap.java - busStops和busServices都是这样的实例.

class HashMapO<K,V> {
  private HashMap<K,V> map;

  public HashMapO() {
    map = new HashMap<>();
  }

  public void put(K key, V value) {
    map.put(key, value);
  }

  public Optional<V> get(K key) {
    return Optional.ofNullable(map.get(key));
  }

  public Stream<Map.Entry<K,V>> entries() {
    return map.entrySet().stream();
  }
}
Run Code Online (Sandbox Code Playgroud)

averageStops.java

  public double averageNumberOfBusesPerStop() {
    double results = busStops.entries()
//return a stream of key value entries in busStops' hashmap.

        .filter(x -> x.getValue().getBusServices())
//for each entry, get the value(e.g. the busStop) and …
Run Code Online (Sandbox Code Playgroud)

java functional-programming

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

在扩展的容器中将对齐控件浮动到左上角和右下角?

我的应用程序中有一个布局,其中包含一些文本和一个时间戳。我希望时间戳(图片中的时钟图标)在展开的小部件的左下角,而文本(图片中的“ what”字符串)应从右上角开始。

表示:

|text|              |
|    -----------    |
|    empty space    |
|    -----------    |
|              |time|
Run Code Online (Sandbox Code Playgroud)

目前,我在下面管理的内容将它们与最左侧和右侧对齐,但是它们似乎受到Column小部件的约束,因此它们与小部件的中心对齐。而且我似乎无法扩展到另一个扩展版中。

在此处输入图片说明

小部件代码:

return new Container(
      child: new Row(
        children: <Widget>[
          new Column(
            children: <Widget>[
              new MaterialButton(
                minWidth: 60.0,
                child: new Icon(Icons.keyboard_arrow_up),
                onPressed: () => null,
              ),
              new Container(
                padding: new EdgeInsets.all(5.0),
                child: new Text("1231"),
              ),
              new MaterialButton(
                minWidth: 60.0,
                child: new Icon(Icons.keyboard_arrow_down),
                onPressed: () => null,
              ),
            ],
          ),
          new Expanded(
            // child: new Container(
            // padding: EdgeInsets.all(10.0),
            child: new Column(
              // mainAxisAlignment: …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

在颤振中使用自定义脚手架复制 GlobalKey

我正在尝试按照这个 github 问题在颤振中实现自定义脚手架:https : //github.com/flutter/flutter/issues/19606

import 'package:flutter/material.dart';

class MyCustomScaffold extends Scaffold {
  static GlobalKey<ScaffoldState> _keyScaffold = GlobalKey();

  MyCustomScaffold({
    AppBar appBar,
    Widget body,
    Widget floatingActionButton,
    FloatingActionButtonLocation floatingActionButtonLocation,
    FloatingActionButtonAnimator floatingActionButtonAnimator,
    List<Widget> persistentFooterButtons,
    Widget drawer,
    Widget endDrawer,
    Widget bottomNavigationBar,
    Widget bottomSheet,
    Color backgroundColor,
    bool resizeToAvoidBottomPadding = true,
    bool primary = true,
  }) : super(
          key: _keyScaffold,
          appBar: endDrawer != null &&
                  appBar.actions != null &&
                  appBar.actions.isNotEmpty
              ? _buildEndDrawerButton(appBar)
              : appBar,
          body: body,
          floatingActionButton: floatingActionButton,
          floatingActionButtonLocation: floatingActionButtonLocation,
          floatingActionButtonAnimator: floatingActionButtonAnimator,
          persistentFooterButtons: persistentFooterButtons,
          drawer: drawer, …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

替换列表中与KDB Q中的子字符串不匹配的元素

我将如何遍历KDB Q中的列表并替换不符合某些子字符串条件的元素?

逻辑示例伪代码:

list.stream()
    .forEach(x -> {
        if (x matches substring) :
            newList.add(x)
        else :
            newList.add("")
     })
Run Code Online (Sandbox Code Playgroud)

当前列表:

S: ("Lint"; "Stack"; "Linode"; "Overflow";"Linux")
Run Code Online (Sandbox Code Playgroud)

要匹配的子字符串在"Li"这里。这样,字符串“ Stack”和“ Overflow”被空字符串替换,因为它们不包含子字符串。

结果列表:

S: ("Lint"; ""; "Linode"; "";"Linux")
Run Code Online (Sandbox Code Playgroud)

kdb

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

如何使用样式组件定位 Material UI Dialog 的背景颜色属性?

我正在寻找Dialog使用样式组件更改Material UI 组件背景的颜色。

我找到了关于如何做到这一点的线程,但我不确定如何将其应用于样式组件。

我目前有一个StyledDialog这样的:

const StyledDialog = styled(Dialog).attrs({

  classes: { paper: 'container' },
  keepMounted: true,
  'aria-labelledby': 'alert-dialog-slide-title',
  'aria-describedby': 'alert-dialog-slide-description'
})`
  .container {
    border-radius: 0;
  }
`;
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

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

Storybook 需要导出默认的 Ant Design 组件以应用样式

我希望使用 Ant Design 设计我的一些 React 组件并在 Storybook 中记录它们。

故事书和组件都编写正确且工作正常。

modal.stories.js

import React from "react";
import { action } from "@storybook/addon-actions";
import { Button } from "@storybook/react/demo";
import { BasicModal } from "./BasicModal";
import { Modal } from "antd"; // IF I REMOVE THIS ANT DESIGN DOESN'T APPLY.

export default {
  title: "Modals"
};

export const basicModal = () => <BasicModal visible={true} />;
export const basicModal2 = () => <Modal visible={true} />; //IF I REMOVE THIS ANT DESIGN DOESN'T APPLY.

Run Code Online (Sandbox Code Playgroud)

BasicModal.tsx …

reactjs antd storybook

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

如何更改 Ant Design 卡片组件的标题字体?

如何更改标题字体但保留 Ant Design 的 Card 组件子组件的默认字体?

样本卡组件:

// How to change title style
<Card title="Default" extra={<a href="#">More</a>} style={{ width: 300 }}>
  <p>Card content</p>
  <p>Card content</p>
  <p>Card content</p>
</Card>
Run Code Online (Sandbox Code Playgroud)

javascript reactjs antd

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