Skip to content

Instantly share code, notes, and snippets.

@masashi-sutou
Last active April 23, 2019 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masashi-sutou/4e4dd3966b97e8f6ba604837315a7857 to your computer and use it in GitHub Desktop.
Save masashi-sutou/4e4dd3966b97e8f6ba604837315a7857 to your computer and use it in GitHub Desktop.
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),
);
}
}
@masashi-sutou
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment