mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 23:39:14 +00:00
add web_dashboard API (#333)
* add web_dashboard sample * add docs * address code review comments * restructure web_dashboard * set up provider and mock service * add copyright headers, use relative imports * add API class, add tests * fmt * rename services -> API, remove data library * use new API in app * add stream to items api * convert from StreamBuilder to StreamProvider * add subscription to Entry API * rename API classes * address comments * Update README.md * update README * remove routing_demo
This commit is contained in:
49
experimental/web_dashboard/lib/src/pages/home.dart
Normal file
49
experimental/web_dashboard/lib/src/pages/home.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../api/api.dart';
|
||||
import 'item_details.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
var api = Provider.of<DashboardApi>(context);
|
||||
|
||||
return Scaffold(
|
||||
body: StreamProvider<List<Item>>(
|
||||
initialData: [],
|
||||
create: (context) => api.items.allItemsStream(),
|
||||
child: Consumer<List<Item>>(
|
||||
builder: (context, items, child) {
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, idx) {
|
||||
return ListTile(
|
||||
title: Text(items[idx].name),
|
||||
onTap: () {
|
||||
_showDetails(items[idx], context);
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: items.length,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
api.items.insert(Item('Coffees Drank'));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDetails(Item item, BuildContext context) {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
|
||||
return ItemDetailsPage(item);
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user