| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import 'package:flutter/material.dart';
- import 'package:twong/api/index.dart';
- import 'package:twong/utils/index.dart';
- import 'package:twong/router/index.dart';
- import 'package:twong/models/index.dart';
- import 'package:twong/widgets/sliver_bar.dart';
- import 'package:twong/widgets/search_bar.dart';
- import 'package:twong/widgets/product_item.dart';
- class ProductListPage extends StatefulWidget {
- final String _keyword;
- ProductListPage(this._keyword, {Key key}): super(key: key);
- @override
- State<StatefulWidget> createState() {
- return _ProductListPageState(_keyword);
- }
- }
- class _ProductListPageState extends State<ProductListPage> {
- final String _keyword;
- ScrollController _scrollController = ScrollController();
- _ProductListPageState(this._keyword);
- Future<List<Product>> _getSearchData() {
- return Network.inst.search(_keyword);
- }
- Widget _buildList () {
- return FutureBuilder(
- future: _getSearchData(),
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- List<Product> data = List<Product>();
- data = snapshot.data;
- if (data.length > 0) {
- return SliverPadding(
- padding: EdgeInsets.all(2),
- sliver: SliverGrid(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 2,
- childAspectRatio: 5 / 6,
- ),
- delegate: SliverChildBuilderDelegate((context, index) =>
- ProductItem(index, data), childCount: data.length),
- ),
- );
- } else {
- return SliverToBoxAdapter(
- child: Container(
- padding: EdgeInsets.only(top: 200),
- child: Text('抱歉,没有找到您想要的宝贝!', textAlign: TextAlign.center,),
- )
- );
- }
- }else {
- return SliverToBoxAdapter(
- child: Container(
- padding: EdgeInsets.only(top: 200),
- child: Center(
- child: CircularProgressIndicator(),
- ),
- ),
- );
- }
- },
- );
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: SearchBar(GestureDetector(
- onTap: () { Navigator.pushNamed(context, RouteNames.home); },
- child: Container(
- child: Center(child: Icon(Icons.arrow_back_ios_outlined, color: Colors.white, size: 20.px)),
- ),
- )),
- body: CustomScrollView(
- controller: _scrollController,
- slivers: <Widget>[
- SliverBar(),
- _buildList(),
- ],
- ),
- floatingActionButton: Container(
- width: 40,
- height: 35,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(3),
- color: Color.fromRGBO(12, 12, 12, 0.6),
- ),
- child: IconButton(
- icon: Icon(Icons.arrow_upward, color: Colors.white),
- onPressed: () {
- _scrollController.animateTo(0, duration: Duration(seconds: 1), curve: Curves.easeInOut);
- },
- ),
- ),
- );
- }
- }
|