我如何读取Future <List <GeneratorResult >>类型

时间:2019-08-07 17:42:33

标签: android flutter dart

请尝试使用表中的select max(id)来实现一个简单的查询,并且我想读取该id,我试图将Future>转换为int,但它不起作用,它不起作用接受演员表我应该怎么做才能从中读取数据

 onPressed: () async {

                              final dao = Provider.of<ClientDao>(context);
                              final client = Client(
                                nom: prenomController.text,
                                prenom: nameController.text,
                                ddn: ddnController.text,
                                ville: adresseController.text,
                                ncd: numeroController.text ,
                              );
                              int id;
                              dao.insertClient(client);
                              Future<List<GeneratorResult>> c = dao.Generator();
                              String a = c.toString();
                              id = int.parse(a); //line 462

                              final dao1 = Provider.of<CommandeDao>(context);
                              final commande = Commande( Clientid: id, completed: true);
                              dao1.insertCommande(commande);

Generator()函数的实现是:

@UseDao(
    tables: [Clients, Commandes],
  queries: {
    'Generator':
    'SELECT max(clients.id_client) AS maxclientid FROM clients;'
  },
)

错误是:

E/flutter (20773): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FormatException: Invalid radix-10 number (at character 1)
E/flutter (20773): Instance of 'Future<List<GeneratorResult>>'
E/flutter (20773): ^
E/flutter (20773): 
E/flutter (20773): #0      int._throwFormatException (dart:core-patch/integers_patch.dart:131:5)
E/flutter (20773): #1      int._parseRadix (dart:core-patch/integers_patch.dart:157:16)
E/flutter (20773): #2      int._parse (dart:core-patch/integers_patch.dart:100:12)
E/flutter (20773): #3      int.parse (dart:core-patch/integers_patch.dart:63:12)
E/flutter (20773): #4      HomePage.build.<anonymous closure> (package:inwi_app/HomePage.dart:462:40)
E/flutter (20773): #5      _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter (20773): #6      HomePage.build.<anonymous closure> (package:inwi_app/HomePage.dart:448:40)
E/flutter (20773): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter (20773): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter (20773): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (20773): #10     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (20773): #11     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
E/flutter (20773): #12     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (20773): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (20773): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (20773): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (20773): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (20773): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (20773): #18     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (20773): #19     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (20773): #20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (20773): #21     _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter (20773): #22     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)

1 个答案:

答案 0 :(得分:1)

onPressed函数的小部件是什么? 我假设onPressed总是返回void,并且要使用Future,您必须放async 为了您的功能

onPressed: () async {
 //code here
}