Skip to content

Commit

Permalink
Make the app responsive to orientation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanSobhy committed Apr 7, 2021
1 parent d21b5f0 commit 1f79653
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 17 deletions.
Binary file added assets/icons/area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/currency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/digital_storage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/length.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/mass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/power.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 19 additions & 10 deletions lib/screens/category_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class CategoryScreen extends StatefulWidget {
}

class _CategoryScreenState extends State<CategoryScreen> {

List<Category> categories;
static const _categoryNames = <String>[
'Length',
Expand Down Expand Up @@ -44,15 +43,25 @@ class _CategoryScreenState extends State<CategoryScreen> {
);
}




ListView _buildCategoryWidgets(List<Category> categories) {
return ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
return categories[index];
});
Widget _buildCategoryWidgets(List<Category> categories) {
if (MediaQuery.of(context).orientation == Orientation.portrait) {
return ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
return categories[index];
});
} else {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
childAspectRatio: 3
),itemCount: categories.length,
itemBuilder: (context, index) {
return categories[index];
});
}
}

AppBar _buildAppBar() {
Expand Down
33 changes: 26 additions & 7 deletions lib/screens/converter_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,32 @@ class _ConverterScreenState extends State<ConverterScreen> {
appBar: AppBar(
title: Text(widget.name),
),
body: Column(

children: [
buildInput(),
buildArrows(),
buildOutput(),
],
body: OrientationBuilder(
builder: (context,orientation){
if(orientation==Orientation.portrait){
return Column(
children: [
buildInput(),
buildArrows(),
buildOutput(),
],
);
} else
{
return Center(
child: Container(
width: 450,
child: ListView(
children: [
buildInput(),
buildArrows(),
buildOutput(),
],
),
),
);
}
},
),
);
}
Expand Down

0 comments on commit 1f79653

Please sign in to comment.