search_list 1.0.0 search_list: ^1.0.0 copied to clipboard
A new Flutter package.
import 'package:flutter/material.dart';
import 'package:search_list/search_list.dart';
void main() => 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(
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> {
ScrollController _scrollController;
List<String> _list = [];
List<int> ser = [];
@override
void initState() {
for (int i = 1; i <= 100; i++) {
_list.add("$i");
}
_scrollController = ScrollController();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Search(
itemheight: 30,
callback: (value) {
ser = value;
setState(() {});
},
list: _list,
controll: _scrollController,
endwidget: Text(""),
),
),
body: ListView.builder(
controller: _scrollController,
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return SizedBox(
height: 30,
child: Text(
_list[index],
style: TextStyle(
color: ser.contains(index) ? Colors.red : Colors.black,
),
),
);
},
));
}
}