我想在应用程序通知到达时显示小吃店。但是当我在第一个屏幕上配置 firebase 时,snackbar 仅在用户在该屏幕上时显示。我尝试创建一个类来获取 BuildContext 并基于它显示小吃店但不起作用并且不显示小吃店。
这是我的 HomeScreen.dart:
class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () {
NotificationManger.init(context: context);
Fcm.initConfigure();
});
}
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, Store<AppState>>(
converter: (store) => store,
onInit: (store) => initApp(store),
builder: (context, store) {
return BlocProvider<HomeBloc>(
create: (context) {
return HomeBloc(homeRepository: homeRepository)..add(ScreenOpened());
},
child: BlocListener<HomeBloc, HomeState>(
listener: (context, state) async {},
child: BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) {
return Scaffold(
key: _scaffoldKey,
...
);
},
),
),
); …Run Code Online (Sandbox Code Playgroud) 我创建了一个容器输入的表单。我循环遍历输入列表来创建表单。我的变量是:
List fields = [
{
'label': Strings.firstName,
'controller': _fnameController,
'validator': (val) => Validation.mustFilled(val),
},
{
'label': Strings.lastName,
'controller': _lnameController,
'validator': (val) => Validation.mustFilled(val),
},
{
'label': Strings.phoneNumber,
'controller': _mobileController,
'validator': (val) => Validation.mobile(val),
},
];
Run Code Online (Sandbox Code Playgroud)
和我的 TextEditingController 定义:
static TextEditingController _fnameController = TextEditingController();
static TextEditingController _lnameController = TextEditingController();
static TextEditingController _mobileController = TextEditingController();
Run Code Online (Sandbox Code Playgroud)
我从上一个屏幕获取输入值并在 initState 中设置输入:
@override
void initState() {
super.initState();
_fnameController.text = widget.userProfile.firstName;
_lnameController.text = widget.userProfile.lastName;
_mobileController.text = widget.userProfile.phoneNumber;
}
for (var item in fields)
Container(
margin: EdgeInsets.symmetric(vertical: …Run Code Online (Sandbox Code Playgroud) 我在 flutter 应用程序中使用 bloc,我的问题是当产生新状态时视图不会更新。我想将新消息添加到我的消息列表中。我使用新数据产生相同的状态,但在将新消息添加到列表后我的视图没有更新。集团:
class ChatBloc extends Bloc<ChatEvent, ChatState> {
@override
ChatState get initialState => ChatInitial();
@override
Stream<ChatState> mapEventToState(ChatEvent event) async* {
if (event is AddToMessages) {
yield* _mapAddToMessagesEventToState(event.chatMessage);
}
}
Stream<ChatState> _mapAddToMessagesEventToState(ChatMessage chatMessage) async* {
List<ChatMessage> chatMessages = (state as DataLoaded).chatMessages;
chatMessages.insert(0, chatMessage);
yield DataLoaded(chatMessages: chatMessages);
}
}
Run Code Online (Sandbox Code Playgroud)
事件:
abstract class ChatEvent extends Equatable {}
class AddToMessages extends ChatEvent {
final ChatMessage chatMessage;
AddToMessages({@required this.chatMessage});
@override
List<Object> get props => [chatMessage];
}
Run Code Online (Sandbox Code Playgroud)
状态:
abstract class ChatState extends Equatable { …Run Code Online (Sandbox Code Playgroud) 我的服务器只接受http(不接受https)。当我调用 api 时,axios 会自动将 http 更改为 https。
我在这里创建 axios 实例:
export const axiosAgent = axios.create({
baseURL: "http://xxx.xxx.xxx/api/v1/",
});
Run Code Online (Sandbox Code Playgroud)
但是在浏览器中http变成了https,所以变成了:https://xxx.xxx.xxx/api/v1/all
我得到net::ERR_NAME_NOT_RESOLVED
我怎样才能防止这种情况发生?
更新 请求标头:
Provisional headers are shown
Accept: application/json, text/plain, */*
Access-Control-Allow-Origin: *
Referer: http://localhost:3000/patients
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
并且没有响应头。
现在我明白了net::ERR_SSL_PROTOCOL_ERROR
我有像/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNywtQFdBRkxOUlNSMj5aYVpQYEpRUk//....的 Base64 图像字符串。
我想要做的是将这个图像保存在临时文件夹中,并使用该文件地址在我的应用程序中显示图像。
我怎样才能做到这一点?
将数据保存在存储中是否会降低性能?例如我们在vue中有一个应用程序,我通过api从服务器获取客户数据。并将其存储在 vuex 中,我可以设置一些过滤器来获取过滤后的数据。这是我的 vuex 的状态。
export const state = () => ({
allCustomers: [],
hasError: false,
loading: false,
searchForm: {
name: "",
nationalCode: "",
mobile: ""
},
filterForm: {
minAge: "",
maxAge: "",
minVisit: "",
maxVisit: "",
gender: ""
},
tagForm: {
visitTag: "",
serviceTag: ""
}
});
Run Code Online (Sandbox Code Playgroud)
我获取数据的请求代码位于操作部分:
export const actions = {
async getCustomer({ commit, state }, API) {
commit(`${ActionsTypes.CHANGE_HAS_ERROR}`, false);
commit(`${ActionsTypes.CHANGE_LOADING}`, true);
commit(`${ActionsTypes.CLEAR_ARRAY}`);
try {
const {
data: { data }
} = await API.get("api/admin/customer", {
params: …Run Code Online (Sandbox Code Playgroud) 我按照本教程添加到react-native-web项目中react-native。但我在添加react-native-vector-icons到项目时遇到错误。
./node_modules/react-native-vector-icons/lib/create-icon-set.js
SyntaxError: /home/hamidreza/Desktop/myApp/node_modules/react-native-vector-icons/lib/create-icon-set.js: Support for the experimental syntax 'classProperties' isn't currently enabled (43:22):
41 |
42 | class Icon extends PureComponent {
> 43 | static propTypes = {
| ^
44 | allowFontScaling: PropTypes.bool,
45 | name: IconNamePropType,
46 | size: PropTypes.number,
Run Code Online (Sandbox Code Playgroud)
我也将我的更改babel.config.js为:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'@babel/plugin-proposal-class-properties',
{
loose: true,
},
],
],
};
Run Code Online (Sandbox Code Playgroud)
或者
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'@babel/plugin-proposal-class-properties' …Run Code Online (Sandbox Code Playgroud) javascript babeljs react-native react-native-web react-native-vector-icons
我正在使用react-native-firebase v6来处理推送通知。由于此版本中没有创建频道 ID功能,在 React Native 项目中创建频道 ID 的解决方案是什么?