flutter开发小技巧

118 阅读2分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。 今天我会与大家分享flutter开发中的 三个小技巧

flutter - URL出现在网站名称的位置

从Android Studio运行时: enter image description here 托管后: enter image description here 我希望我的网站名称显示在该位置。 因此,如果有人可以帮助我,谢谢!

最佳答案

您需要设置MaterialApp的标题。像这样:

  MaterialApp(
      title: 'Welcome - Ajith'

flutter - 如何注意用户何时松开手指

我有一个listView.Builder,想在用户在屏幕上松开手指时根据scrollController的位置进行某些计算吗?

计算部分很容易抖动,但是如何注意到用户从滚动中释放手指来执行某些操作?

最佳答案

使用NotificationListener窗口小部件。 Here是它的简短片段。

您可能想要的代码如下所示:

@override
Widget build(BuildContext context) {    
    return NotificationListener<ScrollNotification>(
        onNotification: (notification) {
            if (notification is ScrollStartNotification) {
                debugPrint('Started');
            }
            if (notification is ScrollUpdateNotification) {
                debugPrint('Updated');
            }
            if (notification is ScrollEndNotification) {
                debugPrint('Ended');
            }
            return false;
        },
        child: YourListView(),
    );
}   

flutter - 如何创建联系人列表

这是我要从中将信息导入到ContactsPage的contacts_data页面:

class Contact {
  final String fullName;
   final String email;

   const Contact({this.fullName, this.email});
}


const kContacts = const <Contact>[
  const Contact(
  fullName: 'Romain Hoogmoed',
  email:'romain.hoogmoed@example.com'
  ),
   const Contact(
      fullName: 'Emilie Olsen',
      email:'emilie.olsen@example.com'
  ),
  const Contact(
       fullName: 'Téo Lefevre',
      email:'téo.lefevre@example.com'
   ),
  const Contact(
      fullName: 'Nicole Cruz',
      email:'nicole.cruz@example.com'
  ),
  const Contact(
      fullName: 'Ramna Peixoto',
      email:'ramna.peixoto@example.com'
  ),
  const Contact(
      fullName: 'Jose Ortiz',
      email:'jose.ortiz@example.com'
  ),
  const Contact(
     fullName: 'Alma Christensen',
     email:'alma.christensen@example.com'
  ),
  const Contact(
     fullName: 'Sergio Hill',
     email:'sergio.hill@example.com'
  ),
  const Contact(
     fullName: 'Malo Gonzalez',
     email:'malo.gonzalez@example.com'
 ),
 const Contact(
     fullName: 'Miguel Owens',
     email:'miguel.owens@example.com'
 ),
  const Contact(
     fullName: 'Lilou Dumont',
     email:'lilou.dumont@example.com'
 ),
  const Contact(
     fullName: 'Ashley Stewart',
     email:'ashley.stewart@example.com'
  ),
  const Contact(
       fullName: 'Roman Zhang',
      email:'roman.zhang@example.com'
 ),
  const Contact(
     fullName: 'Ryan Roberts',
     email:'ryan.roberts@example.com'
 ),
 const Contact(
     fullName: 'Sadie Thomas',
     email:'sadie.thomas@example.com'
 ),
 const Contact(
     fullName: 'Belen Serrano',
     email:'belen.serrano@example.com '
  )];


我修复了代码,有些小部件不可用。

    class ContactsPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              title: new Text("Contacts"),
            ),
            body: new ContactList(kContacts));
      }
    }

    const kContacts = const <Contact>[
      const Contact(
          fullName: 'Romain Hoogmoed', email: 'romain.hoogmoed@example.com'),
      const Contact(fullName: 'Emilie Olsen', email: 'emilie.olsen@example.com')
    ];

    class ContactList extends StatelessWidget {
      final List<Contact> _contacts;

      ContactList(this._contacts);

      @override
      Widget build(BuildContext context) {
        return new ListView.builder(
          padding: new EdgeInsets.symmetric(vertical: 8.0),
          itemBuilder: (context, index) {
            return new _ContactListItem(_contacts[index]);
          },
          itemCount: _contacts.length,
        );
      }
    }

    class _ContactListItem extends ListTile {
      _ContactListItem(Contact contact)
          : super(
                title: new Text(contact.fullName),
                subtitle: new Text(contact.email),
                leading: new CircleAvatar(child: new Text(contact.fullName[0])));
    }

    class Contact {
      final String fullName;
      final String email;

      const Contact({this.fullName, this.email});
    }

请让我知道这对你有没有用。