我正在尝试从我的颤振应用程序中的时间选择器中格式化选定的时间。我不知道为什么,但事实证明这比它应该的要困难得多。我想要达到的最终结果是小时:分钟或下午 5:00。用户从时间选择器小部件中选择时间后,这将显示在框容器中。我有一个名为 'timeFormater()' 的方法,它将格式化选择的时间,但是当我运行我的代码时,我收到错误'flutter: type 'TimeOfDay' is not a subtype of type 'Widget'。是否有更简单的方法/方法来格式化 TimeOfDay()?
我的代码:
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'dart:io' show Platform;
class DateTimePicker extends StatefulWidget {
@override
_DateTimePickerState createState() => _DateTimePickerState();
}
class _DateTimePickerState extends State<DateTimePicker> {
DateTime _date = new DateTime.now();
TimeOfDay _time = new TimeOfDay.now();
Duration initialtimer = new Duration();
DateTime _datePicked;
TimeOfDay _timePicked;
@override
void initState() {
// timeController.addListener(_time);
}
@override
Widget build(BuildContext context) {
return Container(
child: Column( …
Run Code Online (Sandbox Code Playgroud) I'm trying to include a circle profile image button on my sliver app bar but the sliver app bar isn't quite rendering it right. This is what i'm getting, how can I achieve a circle profile image on a sliver app bar?
My Code:
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Home'),
leading: Container(),
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () {}),
Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
child: Container(
height: 30,
width: 30, …
Run Code Online (Sandbox Code Playgroud) 这个问题与此非常相似,但解释对我的用例并没有太大帮助。我有一个 Future 类型的方法,它返回一个 bool 执行对 cloud firestore 的查询,以检查用户输入的用户名是否已经存在。
static Future<bool> doesNameAlreadyExist(String value, String
name) async{
final QuerySnapshot result = await Firestore.instance
.collection('users')
.where(value, isEqualTo: name)
.limit(1)
.getDocuments();
final List<DocumentSnapshot> documents = result.documents;
return documents.length == 1;
Run Code Online (Sandbox Code Playgroud)
}
有没有办法从 Future 获取返回类型的 bool
当我尝试在我的 flutter 应用程序的警报对话框中添加带有日期和时间选择器的下拉菜单时,我遇到了 UI 呈现问题。一段时间以来,我一直在尝试解决此问题,但无济于事。这是我得到的输出:
我的代码:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:test_prep/utils/Reminder.dart';
import 'package:intl/intl.dart';
class RemindersPage extends StatefulWidget {
@override
_RemindersPageState createState() => _RemindersPageState();
}
class _RemindersPageState extends State<RemindersPage> {
final TextEditingController _titleController = new
TextEditingController();
List<DropdownMenuItem<Future>> dateDrop = [];
List<DropdownMenuItem<Future>> timeDrop = [];
int selected = null;
void loadDateData() {
dateDrop = [];
dateDrop.add(new DropdownMenuItem(
child: new Text('Pick Date'),
value: _selectedDate(context),
));
}
void loadTimeData() {
timeDrop = [];
timeDrop.add(new DropdownMenuItem(
child: new Text('Pick a Time'), …
Run Code Online (Sandbox Code Playgroud) android-alertdialog dart drop-down-menu android-studio flutter