backdrop_material_widget 1.0.6
backdrop_material_widget: ^1.0.6 copied to clipboard
Backdrop component of Material Components 2.0.
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:backdrop_material_widget/backdrop_material_widget.dart';
import 'one_page_screen.dart';
void main() => runApp(MyApp());
List<String> genList(int length) => List<String>.generate(length, (index) => 'Item $index');
class ProviderData extends InheritedWidget {
const ProviderData({
Key key,
this.data,
@required Widget child,
}): assert(child != null),
super(key: key, child: child);
final String data;
static ProviderData of(BuildContext context) => context.dependOnInheritedWidgetOfExactType<ProviderData>();
@override
bool updateShouldNotify(ProviderData old) => false;
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final GlobalKey<BackdropScaffoldState> _key = GlobalKey();
final destinations = [
NavigationDestination(
icon: const Icon(Icons.title),
title: const Text('Empty page'),
child: (_) => const OnePage()
),
NavigationDestination(
icon: const Icon(Icons.title),
title: const Text('Page list'),
subTitle: const Text('With infinite list length'),
child: (context){
return FutureBuilder<List<String>>(
future: compute<int, List<String>>(genList, 1000),
builder: (context, snapshot){
if(!snapshot.hasData)
return const Center(
child: CircularProgressIndicator(),
);
if(snapshot.data.isEmpty)
return const Center(
child: Text('List is empty'),
);
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) => ListTile(title: Text(snapshot.data[index]),),
);
},
);
}
),
NavigationDestination(
icon: const Icon(Icons.title),
title: const Text('Test 3'),
subTitle: const Text('Page with action'),
actions: <Widget>[
IconButton(icon: const Icon(Icons.settings), onPressed: () => _key.currentState.callSnackBar(const SnackBar(content: Text('Action!'))))
],
child: (context){
return Container(
color: Colors.blueGrey,
child: Center(
child: FlatButton(child: Text('Open persisten bottom sheet') , onPressed: () {
Backdrop.of(context).showPersistentBottomSheet(context: context, background: Colors.greenAccent, builder: (context){
return Container(
child: Center(
child: RawMaterialButton(onPressed: () => ControllerBottomSheet.of(context).close(), child: Text('Close'),),
),
);
});
}),
),
);
}
)
];
return ProviderData(
data: 'Backdroop inherited provide',
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.green,
brightness: Brightness.dark
),
home: BackdropScaffold.navigation(key: _key, titleAppBar: Text('Backdrop example'), destinations: destinations),
),
);
}
}
class OnePage extends StatelessWidget {
const OnePage();
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: FlatButton(onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (_) => OnePageScreen())), child: Text(ProviderData.of(context).data)),
),
);
}
}