dart

Flutter / Dart Convert Int to Enum

我是研究僧i 提交于 2020-12-02 00:03:49
问题 Is there a simple way to convert an integer value to enum? I want to retrieve an integer value from shared preference and convert it to an enum type. My enum is: enum ThemeColor { red, gree, blue, orange, pink, white, black }; I want to easily convert an integer to an enum: final prefs = await SharedPreferences.getInstance(); ThemeColor c = ThemeColor.convert(prefs.getInt('theme_color')); // something like that 回答1: int idx = 2; print(ThemeColor.values[idx]); should give you ThemeColor.blue

A non-null String must be provided to a Text widget

谁都会走 提交于 2020-12-01 09:44:12
问题 I'm trying to add the option for the quantity to be adjusted but I get an error saying "A non-null String must be provided to a Text widget" How do I provide this, to this code? trailing: Container( height: 60, width: 60, padding: EdgeInsets.only(left: 10), child: Column( children: <Widget>[ new GestureDetector(child: Icon(Icons.arrow_drop_up), onTap: () {}), new Text(cart_prod_qty), new GestureDetector(child: Icon(Icons.arrow_drop_down), onTap: () {}) ], ), 回答1: You should check null safe

TextEditingController vs OnChanged

人走茶凉 提交于 2020-12-01 09:37:30
问题 I am looking for a better explanation on the benefit of TextEditingController over OnChanged event for a TextField. My understanding is that onChanged's setState notifies all widgets of the change in state variable value. This way any widget (e.g. Text) can simply use the state variable and it will be notified of its changes. My false hopes were TextEditingController would make it even simpler that I won't even need a state variable. Something like below: import "package:flutter/material.dart

Flutter - How to get value from shared preferences in a non-async method

荒凉一梦 提交于 2020-12-01 09:28:27
问题 I am trying to get some values saved in the SharedPreferences from a getter method of a class. But SharedPreferences.getInstance() returns a Future . Is there a way to obtain the SharedPreferences object in a non- async getter methods, for example: import 'package:shared_preferences/shared_preferences.dart'; class MyClass { get someValue { return _sharedPreferencesObject.getString("someKey"); } } Is there something in Dart that is similar to .Result property in C#, for example

Flutter - How to get value from shared preferences in a non-async method

那年仲夏 提交于 2020-12-01 09:28:25
问题 I am trying to get some values saved in the SharedPreferences from a getter method of a class. But SharedPreferences.getInstance() returns a Future . Is there a way to obtain the SharedPreferences object in a non- async getter methods, for example: import 'package:shared_preferences/shared_preferences.dart'; class MyClass { get someValue { return _sharedPreferencesObject.getString("someKey"); } } Is there something in Dart that is similar to .Result property in C#, for example

How do I fix “No pubspec.yaml file found” in flutter?

♀尐吖头ヾ 提交于 2020-12-01 09:07:21
问题 I am using Windows 10 with VS Code, although I also tested it on PowerShell, and both produced the same result: After creating a new flutter program, before editing anything, I tried to run it on my phone, as the Tutorial Says, but I get an error saying "No pubspec.yaml file found". I thought that the issue must be that the default new app setup having an issue, so I used the "flutter_gallery" example. However, this had the exact same issue. I have reinstalled flutter, installed dart 2 on its

Flutter: adjust height of PageView/Horizontal ListView based on current child

前提是你 提交于 2020-12-01 08:59:48
问题 I'm trying to create a carousel with items of variable heights. When using PageView or ListView with horizontal scrolling, I need to give it a constant height, like this: class CarouselVariableHightState extends State<CarouselVariableHight> { double height = 200; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Carousel')), body: ListView( children: <Widget>[ Text('My Carousel'), Container( height: height, child: PageView( children: <Widget>[

Flutter: adjust height of PageView/Horizontal ListView based on current child

有些话、适合烂在心里 提交于 2020-12-01 08:59:22
问题 I'm trying to create a carousel with items of variable heights. When using PageView or ListView with horizontal scrolling, I need to give it a constant height, like this: class CarouselVariableHightState extends State<CarouselVariableHight> { double height = 200; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Carousel')), body: ListView( children: <Widget>[ Text('My Carousel'), Container( height: height, child: PageView( children: <Widget>[

Flutter Remove list item

风流意气都作罢 提交于 2020-12-01 08:19:00
问题 I have a question in my flutter dart script, this my script: List<ReplyTile> replytile = new List<ReplyTile>(); replytile.add( new ReplyTile( member_photo: "photo", member_id: "001", date: "01-01-2018", member_name: "Denis", id: "001", text: "hallo.." ) ); My question is: how to remove items on List<ReplyTile> with id = 001 .. ? Thanks in advance 回答1: removeWhere allows to do that: replytile.removeWhere((item) => item.id == '001') See also List Dartdoc 回答2: In your case this works: replytile

How can I change Drawer icon in flutter?

十年热恋 提交于 2020-12-01 06:11:12
问题 The drawer has this default three horizontal bars as default icon but i want to change it to something else. I have checked the possible options under the Drawer(), but no property seems to be attached to that. PS: I am a beginner in Flutter. 回答1: This should work. Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title:Text('hi'), leading: IconButton( icon: Icon(Icons.accessible), onPressed: () => Scaffold.of(context).openDrawer(), ), ), ); From the docs -> {Widget