尝试将'用作其中一个导入指令的前缀,或对除一个导入指令之外的所有导入指令隐藏该名称 [英] Try using 'as prefix' for one of the imported directives,or hiding the name from all but one of the import

查看:9
本文介绍了尝试将'用作其中一个导入指令的前缀,或对除一个导入指令之外的所有导入指令隐藏该名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经导入了一个Eosdart包,它有action.dart文件,甚至Ffltter也有action.dart文件,所以应该选择哪一个是冲突的。 请帮助消除冲突 我在收到错误的代码中将错误详细信息作为注释提到



class _AddBorrowerState extends State<AddBorrower> {
  eos.Account _account;
  eos.EOSClient _eosClient = eos.EOSClient(
      'http://jungle2.cryptolions.io:80', 'v1',
      privateKeys: ["5JfVW2PtRkAcLbLETevxCwaQuT8NNWvP2eBYCrPRKPBWDgZDEo1"]);

  List<eos.Authorization> auth = [
    eos.Authorization()
      ..actor = 'guru11111111'
      ..permission = 'active'
  ];

  Map data = {
    'acc_name': myController1.text,**error only static member can be accessed in initializers**
    'b_id': '119',
    'location': 'mumbai',
    'b_phone': '11231212',
  };

  List<eos.Action> actions = [
    eos.Action()
      ..account = 'guru11111111'
      ..name = 'addborrower'
      ..authorization = auth   **ERROR only static member can be accessed in initializers**
      ..data = data**error only static member can be accessed in initializers**
  ];
  eos.Transaction transaction = eos.Transaction()..actions = actions;

  void _fetchEOSAccount() {
    _eosClient.getAccount(myController2.text).then((eos.Account account) {
      setState(() {
        _account = account;
      });
    });
  }

  void add() {
    _eosClient.pushTransaction(transaction, broadcast: true).then((trx) {
      print(trx);
    });
  }

  final myController1 = TextEditingController();
  final myController2 = TextEditingController();
  final myController3 = TextEditingController();
  final myController4 = TextEditingController();
  final myController5 = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.teal,
        body: SafeArea(
          child: Column(
            children: <Widget>[
              Card(
                color: Colors.white,
                margin: EdgeInsets.symmetric(vertical: 10, horizontal: 25),
                child: TextField(**//these are textfeild who's value we want to store in eos table **
                  controller: myController1,
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Enter Full Name',
                  ),
                ),
              ),
              Card(
                color: Colors.white,
                margin: EdgeInsets.symmetric(vertical: 10, horizontal: 25),
                child: TextField(
                  controller: myController2,
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Enter ID',
                  ),
                ),
              ),
               Card(
                color: Colors.white,
                child: FlatButton(
                  child: Text('Submit'),
                  onPressed: () {
//                    Navigator.pop(context);
                    _fetchEOSAccount();
                  },
                ),
              ),
              Flexible(
                child: Text('${_account?.toJson()}'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
错误:错误在初始值设定项中只能访问静态成员,这意味着什么?我该怎么办?

推荐答案

编辑

初始化时myController1.text没有值
您可以使用空字符串,并在以后的acion中更新此值

使用

import 'package:eosdart/eosdart.dart' as eos;

和代码前缀

eos.EOSClient(...)

也引用Does Dart have import alias?
和用于显示或隐藏引用What is the difference between "show" and "as" in an import statement?

完整代码

import 'package:flutter/material.dart';
import 'package:eosdart/eosdart.dart' as eos;
import 'package:flutter/foundation.dart';

void main() {
  eos.EOSClient client = eos.EOSClient('http://127.0.0.1:8888', 'v1',
      privateKeys: ["5J9b3xMkbvcT6gYv2EpQ8FD4ZBjgypuNKwE1jxkd7Wd1DYzhk88"]);

  List<eos.Authorization> auth = [
    eos.Authorization()
      ..actor = 'bob'
      ..permission = 'active'
  ];

  Map data = {
    'from': 'bob',
    'to': 'alice',
    'quantity': '0.0001 SYS',
    'memo': '',
  };

  List<eos.Action> actions = [
    eos.Action()
      ..account = 'eosio.token'
      ..name = 'transfer'
      ..authorization = auth
      ..data = data
  ];

  eos.Transaction transaction = eos.Transaction()..actions = actions;

  // will print something like:
  // {transaction_id: c28bf8c168741adb96f3aef8723e953140cc60ecd20cec0d22e5a2dc5cdd5571, processed: {id: c28bf8c168741adb96f3aef8723e953140cc60ecd20cec0d22e5a2dc5cdd5571, block_num: 576745, block_time: 2019-05-03T06:07:54.500, producer_block_id: null, receipt: {status: executed, cpu_usage_us: 216, net_usage_words: 16}, elapsed: 216, net_usage: 128, scheduled: false, action_traces: [{receipt: {receiver: eosio.token, act_digest: 117d5840be4ff21fad764d5d497182916f76e772b279e65e964bccfa7c888331, global_sequence: 576794, recv_sequence: 17, auth_sequence: [[bob, 37]], code_sequence: 1, abi_sequence: 1}, act: {account: eosio.token, name: transfer, authorization: [{actor: bob, permission: active}], data: {from: bob, to: alice, quantity: 0.0001 SYS, memo: }, hex_data: 0000000000000e3d0000000000855c340100000000000000045359530000000000}, context_free: false, elapsed: 73, console: , trx_id: c28bf8c168741adb96f3aef8723e953140cc60ecd20cec0d22e5a2dc5cdd5571, block_num: 576745, block_time: 2019-05-03T06:07:54.500, producer_block_id: null, account_ram_deltas: [], except: null, inline_traces: [{receipt: {receiver: bob, act_digest: 117d5840be4ff21fad764d5d497182916f76e772b279e65e964bccfa7c888331, global_sequence: 576795, recv_sequence: 14, auth_sequence: [[bob, 38]], code_sequence: 1, abi_sequence: 1}, act: {account: eosio.token, name: transfer, authorization: [{actor: bob, permission: active}], data: {from: bob, to: alice, quantity: 0.0001 SYS, memo: }, hex_data: 0000000000000e3d0000000000855c340100000000000000045359530000000000}, context_free: false, elapsed: 2, console: , trx_id: c28bf8c168741adb96f3aef8723e953140cc60ecd20cec0d22e5a2dc5cdd5571, block_num: 576745, block_time: 2019-05-03T06:07:54.500, producer_block_id: null, account_ram_deltas: [], except: null, inline_traces: []}, {receipt: {receiver: alice, act_digest: 117d5840be4ff21fad764d5d497182916f76e772b279e65e964bccfa7c888331, global_sequence: 576796, recv_sequence: 15, auth_sequence: [[bob, 39]], code_sequence: 1, abi_sequence: 1}, act: {account: eosio.token, name: transfer, authorization: [{actor: bob, permission: active}], data: {from: bob, to: alice, quantity: 0.0001 SYS, memo: }, hex_data: 0000000000000e3d0000000000855c340100000000000000045359530000000000}, context_free: false, elapsed: 2, console: , trx_id: c28bf8c168741adb96f3aef8723e953140cc60ecd20cec0d22e5a2dc5cdd5571, block_num: 576745, block_time: 2019-05-03T06:07:54.500, producer_block_id: null, account_ram_deltas: [], except: null, inline_traces: []}]}], except: null}}
  client.pushTransaction(transaction, broadcast: true).then((trx) {
    print(trx);
  });
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

这篇关于尝试将&#39;用作其中一个导入指令的前缀,或对除一个导入指令之外的所有导入指令隐藏该名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆