dart

How to display list of map into DropdownMenuItem in Flutter

心已入冬 提交于 2021-01-28 08:20:38
问题 I'm new with Flutter. I want to display DropdownMenuItem from my list variable. Check out my code. // my list variable List listUserType = [ {'name': 'Individual', 'value': 'individual'}, {'name': 'Company', 'value': 'company'} ]; // items property in DropdownMenuItem return DropdownButtonFormField<List<Map>>( decoration: InputDecoration( prefixIcon: Icon(Icons.settings), hintText: 'Organisation Type', filled: true, fillColor: Colors.white, errorStyle: TextStyle(color: Colors.yellow), ),

Why catchError isn't able to catch the error?

一曲冷凌霜 提交于 2021-01-28 08:11:50
问题 void main() { foo().catchError((error) { print('Error caught = $error'); }); } Future<void> foo() { throw Future.error('FooError'); } As I read the docs: This is the asynchronous equivalent of a "catch" block. If I use catch block, the error is caught. But my catchError isn't able to catch the error, but according to docs it should. Am I doing something wrong? Note: I know I can use return instead of throw and the error will be then caught in catchError as stated by @CopsOnRoad here. My

How can I have the BottomNavigationBar respond to navigation to a new page via AlertDialog?

独自空忆成欢 提交于 2021-01-28 08:08:44
问题 I have a navigation_bar.dart file that handles changing to new pages within my app. Within it, I am using the bottomNavigationBar to build out four different pages based on what tab is currently selected like so: class NavigationBar extends StatefulWidget { @override _NavigationBarState createState() => _NavigationBarState(); } class _NavigationBarState extends State<NavigationBar> { int _selectedIndex = 0; final List<Widget> _pageOptions = <Widget>[ Page1(), Page2(), Page3(), Page4(), ];

Date Countdown Timer

随声附和 提交于 2021-01-28 07:37:03
问题 I'm trying to make countdowns to date and put each countdown in an ItemView in a ListView. I have already the Listview.buillder() but I don't know how to make countdowns which have different values and put them in the Listview. I have seen that there is another similar question but I can't solve my problem with it. Here is my code : home_screen.dart import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import '../recyclerview/data.dart';

Cannot interacted with Google Maps on Flutter Web (google_maps)

耗尽温柔 提交于 2021-01-28 07:34:34
问题 I am just learn about Flutter for website. I need to add some google map javascript API and using google_maps dependencies on pub.dev I follow the example from here, but after debugging with VSCode , i found that I cannot interact with the map at all. No hand tools to drag the map, ore even just to click the maps mode (satellite or map mode). I have tried several example from the example link, from the basics to the controlled example. But I still cannot interact with it. No error on terminal

convert JSON String to the list object in flutter

点点圈 提交于 2021-01-28 07:28:00
问题 I'm still new to the dart flutter. now I'm trying to pull data from the REST API. following the script that I have made: class ChatCard { final String chatdetail_id; final String chatdetail_userfullname; final String chatdetail_userurlphoto; final String chatdetail_message; final int chatdetail_isread; final String chatdetail_datetime; ChatCard({ this.chatdetail_id, this.chatdetail_userfullname, this.chatdetail_userurlphoto, this.chatdetail_message, this.chatdetail_isread, this.chatdetail

Flutter color not chaning on change of index

為{幸葍}努か 提交于 2021-01-28 07:09:01
问题 I want to change the color on the tap of the container. So I just for loop to show container and change color when index is the same. But the issue is index is changing but the color is not. I have checked by the print value of currentIndex is changing but don't know why the color isn't changing I am using a stateful widget Code List categories = [ {'CatID': 0, 'CatName': 'All'}, {'CatID': 1, 'CatName': 'Computer Hardware'}, {'CatID': 2, 'CatName': 'Computer Software'}, {'CatID': 3, 'CatName'

Unit test - How to mock parameters of third-party-library class Dio in flutter

浪尽此生 提交于 2021-01-28 06:30:23
问题 I am trying to test a simple repository class which make a network call using the Dio package that is a dependency injection. Requirement of the Http.post is to send a Map object to a URL with the headers of 'Content-Type': 'application/json . You can see this below: class AuthenticateUserRemoteDataSourceImpl implements AuthenticateUserRepository { final Dio httpClient; AuthenticateUserRemoteDataSourceImpl({@required this.httpClient}); @override Future<Either<Failure, AuthenticateUser>>

How can i refresh the widget on the the page A, when i return from page B?

橙三吉。 提交于 2021-01-28 06:30:16
问题 I have a stateful Page A that contains a widget which is present in a seperate stateful class. The widget fetches a number from sharedPreferences in its initState method and show it and when i click on the widget, it routes to Page B, Page B contains a function that change the number in the sharedPreferences. when i go back i dont see the changes but when i reopen the app or switch to a different tab and come back, i do. 回答1: In page A, when you go to page B use, Navigator.pushNamed(context,

How do I remove a widget in response to user input?

吃可爱长大的小学妹 提交于 2021-01-28 06:07:05
问题 I have a chip. How do I get the chip to disappear when the user has deleted it? I do not understand the code at all from Flutter Docs. I've tried everything. Chip( deleteIcon: Icon(Icons.close, size: 15,), label: Text('Delete me!'), deleteButtonTooltipMessage: 'erase', onDeleted: () {setState(() {print("I want to erase this chip, and eat chips");}); }, ) The docs suggest that this chip (Chip) can be erased. But they don't give much in the way of examples. 回答1: I am assuming that you have this