Last active
April 23, 2019 01:11
-
-
Save masashi-sutou/4e4dd3966b97e8f6ba604837315a7857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:porto/firebase/base_firestore.dart'; | |
import 'package:porto/model/feature_content.dart'; | |
class StoreScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const _StoreScreenState(); | |
} | |
} | |
class _StoreScreenState extends StatelessWidget { | |
const _StoreScreenState({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Example'), | |
), | |
body: ListView.builder( | |
itemCount: 2, | |
itemBuilder: (context, index) { | |
switch (index) { | |
case 0: | |
return _createMainTitle('Feature'); | |
case 1: | |
return _createFeatureSection(context); | |
default: | |
return Container(); | |
} | |
}, | |
), | |
); | |
} | |
ListTile _createMainTitle(String title) { | |
return ListTile( | |
title: Text( | |
title, | |
style: const TextStyle( | |
fontWeight: FontWeight.bold, | |
fontSize: 18, | |
), | |
), | |
); | |
} | |
Widget _createFeatureSection(BuildContext context) { | |
return Container( | |
height: 180, | |
child: FutureBuilder<FeatureContent>( | |
initialData: FeatureContent.fromMap({}), | |
future: BaseFirestore.getFeatureContents(), | |
builder: (context, snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.none: | |
case ConnectionState.waiting: | |
return const Center(child: CircularProgressIndicator()); | |
default: | |
if (snapshot.hasError) { | |
return Center(child: Text(snapshot.error.toString())); | |
} | |
return ListView( | |
scrollDirection: Axis.horizontal, | |
children: List.generate( | |
3, | |
(index) => _createFeature(context, index, snapshot.data), | |
), | |
); | |
} | |
}, | |
), | |
); | |
} | |
Widget _createFeature( | |
BuildContext context, int index, FeatureContent content) { | |
return Card( | |
margin: (index == 2) | |
? const EdgeInsets.symmetric(vertical: 8, horizontal: 18) | |
: const EdgeInsets.only(top: 8, left: 18, bottom: 8), | |
elevation: 4, | |
child: Image.network(content.imageUrl), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
原因判明