1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-12 15:58:32 +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:
John Ryan
2020-03-02 16:04:10 -08:00
committed by GitHub
parent 738b0d9958
commit edf219354e
73 changed files with 2681 additions and 13 deletions

View 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);
}));
}
}

View File

@@ -0,0 +1,22 @@
// 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:web_dashboard/src/api/api.dart';
class ItemDetailsPage extends StatelessWidget {
final Item item;
ItemDetailsPage(this.item);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text('${item.name}'),
),
);
}
}