Skip to content

Null Safety fixes #31 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 126 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ import 'package:flutter/material.dart';
import 'package:responsive_scaffold/responsive_scaffold.dart';

class LayoutExample extends StatelessWidget {
const LayoutExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ResponsiveScaffold(
title: Text('Responsive Layout Example'),
title: const Text('Responsive Layout Example'),
drawer: ListView(
children: <Widget>[
children: const <Widget>[
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings Page'),
Expand All @@ -70,15 +72,15 @@ class LayoutExample extends StatelessWidget {
endDrawer: ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.filter_list),
title: Text('Filter List'),
subtitle: Text('Hide and show items'),
leading: const Icon(Icons.filter_list),
title: const Text('Filter List'),
subtitle: const Text('Hide and show items'),
trailing: Switch(
value: true,
onChanged: (val) {},
),
),
ListTile(
const ListTile(
leading: Icon(Icons.image_aspect_ratio),
title: Text('Size Settings'),
subtitle: Text('Change size of images'),
Expand All @@ -90,9 +92,9 @@ class LayoutExample extends StatelessWidget {
),
),
ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text('Sort List'),
subtitle: Text('Change layout behavior'),
leading: const Icon(Icons.sort_by_alpha),
title: const Text('Sort List'),
subtitle: const Text('Change layout behavior'),
trailing: Switch(
value: false,
onChanged: (val) {},
Expand All @@ -101,27 +103,26 @@ class LayoutExample extends StatelessWidget {
],
),
trailing: IconButton(
icon: Icon(Icons.search),
icon: const Icon(Icons.search),
onPressed: () {},
),
body: Center(
child: RaisedButton(
child: Text('Close'),
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Theme.of(context).accentColor,
onPressed: () {},
child: const Icon(Icons.add),
),
);
}
}


```

### Responsive List
Expand All @@ -141,107 +142,132 @@ class LayoutExample extends StatelessWidget {

``` dart
import 'package:flutter/material.dart';

import 'package:responsive_scaffold/responsive_scaffold.dart';

void main() => runApp(MyApp());
class ListExample extends StatefulWidget {
const ListExample({Key? key}) : super(key: key);

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
_ListExampleState createState() => _ListExampleState();
}

class _MyAppState extends State<MyApp> {
var _scaffoldKey = new GlobalKey<ScaffoldState>();
class _ListExampleState extends State<ListExample> {
final _scaffoldKey = GlobalKey<ScaffoldState>();

late List<String> _items;

@override
void initState() {
_items = List.generate(20, (int index) => "test_$index");
super.initState();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: ResponsiveListScaffold.builder(
scaffoldKey: _scaffoldKey,
detailBuilder: (BuildContext context, int index, bool tablet) {
return DetailsScreen(
// appBar: AppBar(
// elevation: 0.0,
// title: Text("Details"),
// actions: [
// IconButton(
// icon: Icon(Icons.share),
// onPressed: () {},
// ),
// IconButton(
// icon: Icon(Icons.delete),
// onPressed: () {
// if (!tablet) Navigator.of(context).pop();
// },
// ),
// ],
// ),
body: Scaffold(
appBar: AppBar(
elevation: 0.0,
title: Text("Details"),
automaticallyImplyLeading: !tablet,
actions: [
IconButton(
icon: Icon(Icons.share),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
if (!tablet) Navigator.of(context).pop();
},
),
],
),
bottomNavigationBar: BottomAppBar(
elevation: 0.0,
child: Container(
child: IconButton(
icon: Icon(Icons.share),
onPressed: () {},
),
),
),
body: Container(
child: Center(
child: Text("Item: $index"),
),
),
return ResponsiveListScaffold.builder(
scaffoldKey: _scaffoldKey,
detailBuilder: (BuildContext context, int index, bool tablet) {
final i = _items[index];
return DetailsScreen(
body: ExampleDetailsScreen(
items: _items,
row: i,
tablet: tablet,
onDelete: () {
setState(() {
_items.removeAt(index);
});
if (!tablet) Navigator.of(context).pop();
},
onChanged: (String value) {
setState(() {
_items[index] = value;
});
},
),
);
},
nullItems: const Center(child: CircularProgressIndicator()),
emptyItems: const Center(child: Text("No Items Found")),
slivers: const <Widget>[
SliverAppBar(
title: Text("App Bar"),
),
],
itemCount: _items.length,
itemBuilder: (BuildContext context, int index) {
final i = _items[index];
return ListTile(
leading: Text(i),
);
},
bottomNavigationBar: BottomAppBar(
elevation: 0.0,
child: IconButton(
icon: const Icon(Icons.share),
onPressed: () {},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Snackbar!"),
),
);
},
nullItems: Center(child: CircularProgressIndicator()),
emptyItems: Center(child: Text("No Items Found")),
slivers: <Widget>[
SliverAppBar(
title: Text("App Bar"),
child: const Icon(Icons.add),
),
);
}
}

class ExampleDetailsScreen extends StatelessWidget {
const ExampleDetailsScreen({
Key? key,
required List<String> items,
required this.row,
required this.tablet,
required this.onDelete,
required this.onChanged,
}) : _items = items,
super(key: key);

final List<String> _items;
final String row;
final bool tablet;
final VoidCallback onDelete;
final ValueChanged<String> onChanged;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
automaticallyImplyLeading: !tablet,
title: const Text("Details"),
actions: [
IconButton(
icon: const Icon(Icons.share),
onPressed: () {
onChanged("$row ${DateTime.now().toString()}");
},
),
],
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: Text(index.toString()),
);
},
bottomNavigationBar: BottomAppBar(
elevation: 0.0,
child: Container(
child: IconButton(
icon: Icon(Icons.share),
onPressed: () {},
),
IconButton(
icon: const Icon(Icons.delete),
onPressed: onDelete,
),
],
),
bottomNavigationBar: BottomAppBar(
elevation: 0.0,
child: IconButton(
icon: const Icon(Icons.share),
onPressed: () {},
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Snackbar!"),
));
},
),
),
body: Center(
child: Text("Item: $row"),
),
);
}
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lint/analysis_options_package.yaml
Loading