如何添加交互式收藏夹图标

时间:2019-06-26 16:14:58

标签: flutter dart flutter-layout

我正在尝试添加一个收藏夹图标,以将该字段发送到另一个页面。

我已经尝试了另一种解决方案,但是没有任何解决方案。 我认为我想要的是可能的,但是如果那不可能,请说

function Mesh(name) {
  this._name = name;
  this.interval = null;
}

Mesh.prototype.blink = function(delay) {
  var Toggle = false
  this.interval = (() => {
    return setInterval(() => {
      console.log(this._name, " blinking ", "Toggle", Toggle)
      Toggle = !Toggle;
    }, delay);
  })();
  console.log("interval in blink:", this.interval)

}

Mesh.prototype.stopBlink = function(duration) {

  setTimeout(() => {
    console.log("interval in stop: ", this.interval)
    clearInterval(this.interval);
  }, duration);
}

let m = new Mesh("mesh")
m.blink(200)
m.stopBlink(1000)

上一页将字段发送到下一页

import 'package:flutter/material.dart';
import 'Screen_4.dart';

class SearchList extends StatefulWidget {
  SearchList({Key key}) : super(key: key);
  @override
  _SearchListState createState() => _SearchListState();
}

class _SearchListState extends State<SearchList> {
  Widget appBarTitle = Text(
    "------------------->",
    style: TextStyle(color: Colors.white),
  );
  Icon actionIcon = Icon(
    Icons.search,
    color: Colors.white,
  );
  final key = GlobalKey<ScaffoldState>();
  final TextEditingController _searchQuery = TextEditingController();

  List<String> _list;
  bool _IsSearching;
  String _searchText = "";

  _SearchListState() {
    _searchQuery.addListener(() {
      if (_searchQuery.text.isEmpty) {
        setState(() {
          _IsSearching = false;
          _searchText = "";
        });
      } else {
        setState(() {
          _IsSearching = true;
          _searchText = _searchQuery.text;
        });
      }
    });
  }

  @override
  void initState() {
    super.initState();
    _IsSearching = false;
    init();
  }

  void init() {
    _list = List();
    _list.add("Google");
    _list.add("IOS");
    _list.add("Andorid");
    _list.add("Dart");
    _list.add("Flutter");
    _list.add("Python");
    _list.add("React");
    _list.add("Xamarin");
    _list.add("Kotlin");
    _list.add("Java");
    _list.add("RxAndroid");
    _list.add('Lenovo');
    _list.add('PetroChina Company');
    _list.add('Xiaomi');
    _list.add('Uber');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: key,
      appBar: buildBar(context),
      body: ListView(
        padding: EdgeInsets.symmetric(vertical: 8.0),
        children: _IsSearching ? _buildSearchList() : _buildList(),
      ),
    );
  }

  List<ChildItem> _buildList() {
    return _list.map((contact) => ChildItem(contact)).toList();
  }

  List<ChildItem> _buildSearchList() {
    if (_searchText.isEmpty) {
      return _list.map((contact) => ChildItem(contact)).toList();
    } else {
      List<String> _searchList = List();
      for (int i = 0; i < _list.length; i++) {
        String name = _list.elementAt(i);
        if (name.toLowerCase().contains(_searchText.toLowerCase())) {
          _searchList.add(name);
        }
      }
      return _searchList.map((contact) => ChildItem(contact)).toList();
    }
  }

  Widget buildBar(BuildContext context) {
    return AppBar(
      centerTitle: true,
      title: appBarTitle,
      actions: <Widget>[
        IconButton(
          icon: actionIcon,
          onPressed: () {
            setState(
              () {
                if (this.actionIcon.icon == Icons.search) {
                  this.actionIcon = Icon(
                    Icons.close,
                    color: Colors.white,
                  );
                  this.appBarTitle = TextField(
                    controller: _searchQuery,
                    style: TextStyle(
                      color: Colors.white,
                    ),
                    decoration: InputDecoration(
                      prefixIcon: Icon(Icons.search, color: Colors.black),
                      hintText: "Search...",
                      hintStyle: TextStyle(color: Colors.white),
                    ),
                  );
                  _handleSearchStart();
                } else {
                  _handleSearchEnd();
                }
              },
            );
          },
        ),
      ],
    );
  }

  void _handleSearchStart() {
    setState(
      () {
        _IsSearching = true;
      },
    );
  }

  void _handleSearchEnd() {
    setState(
      () {
        this.actionIcon = Icon(
          Icons.search,
          color: Colors.white,
        );
        this.appBarTitle = Text(
          "------------------->",
          style: TextStyle(color: Colors.white),
        );
        _IsSearching = false;
        _searchQuery.clear();
      },
    );
  }
}

class ChildItem extends StatelessWidget {
  final String name;
  ChildItem(this.name);
  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(this.name), //onTap: () => print(name));
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => ShowData(title: this.name),
          ),
        );
      },
    );
  }
}

我想要的是:那个人按下“收藏夹”图标,然后该字段转到另一页。

0 个答案:

没有答案
相关问题