Skip to content
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

[WIP] style/refactor: mode state management issue in main screen #88

Closed
Closed
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
163 changes: 90 additions & 73 deletions lib/screens/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ class _MainScreenState extends State<MainScreen>
title: Text('Add another account'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ConfigurationsScreen(),
));
context,
MaterialPageRoute(
builder: (context) => ConfigurationsScreen(),
),
);
},
),
));
Expand All @@ -149,8 +150,9 @@ class _MainScreenState extends State<MainScreen>
@override
Widget build(BuildContext context) {
super.build(context);
return Consumer3<Mode, Api, GeneralFeatures>(
builder: (context, mode, api, general, child) {
var modeTheme = Provider.of<Mode>(context, listen: false);
return Consumer2<Api, GeneralFeatures>(
builder: (context, api, general, child) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
Expand All @@ -161,28 +163,34 @@ class _MainScreenState extends State<MainScreen>
elevation: 0.0,
leading: Builder(builder: (context) {
return IconButton(
icon: Icon(
Icons.subject,
size: 34,
),
onPressed: () {
Scaffold.of(context).openDrawer();
});
icon: Icon(
Icons.subject,
size: 34,
),
onPressed: () {
Scaffold.of(context).openDrawer();
},
);
}),
actions: <Widget>[
IconButton(
icon: FaIcon(
mode.isLightMode
? FontAwesomeIcons.solidMoon
: FontAwesomeIcons.solidSun,
),
onPressed: () async {
mode.toggleMode();
Provider.of<Settings>(context, listen: false)
.setShowDarkMode(mode.isDarkMode);
await Preferences.saveSettings(
Provider.of<Settings>(context, listen: false));
}),
Consumer<Mode>(
builder: (context, mode, child) {
return IconButton(
icon: FaIcon(
mode.isLightMode
? FontAwesomeIcons.solidMoon
: FontAwesomeIcons.solidSun,
),
onPressed: () async {
mode.toggleMode();
Provider.of<Settings>(context, listen: false)
.setShowDarkMode(mode.isDarkMode);
await Preferences.saveSettings(
Provider.of<Settings>(context, listen: false));
},
);
},
),
],
),
drawer: Drawer(
Expand All @@ -195,7 +203,7 @@ class _MainScreenState extends State<MainScreen>
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image(
image: mode.isLightMode
image: modeTheme.isLightMode
? AssetImage('assets/logo/light_mode.png')
: AssetImage('assets/logo/dark_mode.png'),
),
Expand All @@ -211,41 +219,41 @@ class _MainScreenState extends State<MainScreen>
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
children: [
ShowDiskSpace(),
ExpansionTile(
leading: Icon(Icons.supervisor_account,
color:
mode.isLightMode ? Colors.black : Colors.white),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
title: Text('Accounts'),
children: _getAccountsList(api, mode, general),
children: _getAccountsList(api, modeTheme, general),
),
ExpansionTile(
initiallyExpanded: true,
leading: Icon(Icons.sort,
color:
mode.isLightMode ? Colors.black : Colors.white),
title: Text(
'Filters',
),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
title: Text('Filters'),
children: general.filterTileList,
),
ExpansionTile(
initiallyExpanded: true,
leading: Icon(Icons.sort,
color:
mode.isLightMode ? Colors.black : Colors.white),
title: Text(
'Labels',
),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
title: Text('Labels'),
children: (general.listOfLabels as List<String>)
.map((e) => LabelTile(label: e))
.toList(),
),
ListTile(
leading: Icon(Icons.history,
color:
mode.isLightMode ? Colors.black : Colors.white),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
onTap: () {
Navigator.pop(context);
Navigator.push(
Expand All @@ -257,8 +265,9 @@ class _MainScreenState extends State<MainScreen>
),
ListTile(
leading: Icon(Icons.folder_open,
color:
mode.isLightMode ? Colors.black : Colors.white),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
onTap: () {
Navigator.pop(context);
Navigator.push(
Expand All @@ -271,8 +280,9 @@ class _MainScreenState extends State<MainScreen>
),
ListTile(
leading: Icon(Icons.settings,
color:
mode.isLightMode ? Colors.black : Colors.white),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
onTap: () {
Navigator.pop(context);
Navigator.push(
Expand All @@ -285,15 +295,16 @@ class _MainScreenState extends State<MainScreen>
),
ListTile(
leading: Icon(Icons.info_outline,
color:
mode.isLightMode ? Colors.black : Colors.white),
color: modeTheme.isLightMode
? Colors.black
: Colors.white),
onTap: () {
showAboutDialog(
context: context,
applicationVersion: packageInfo.version,
applicationIcon: Image(
height: 75,
image: mode.isLightMode
image: modeTheme.isLightMode
? AssetImage(
'assets/logo/light_mode_icon.png')
: AssetImage(
Expand Down Expand Up @@ -345,8 +356,7 @@ class _MainScreenState extends State<MainScreen>
],
),
bottomNavigationBar: BottomNavigationBar(
backgroundColor:
Provider.of<Mode>(context).isDarkMode ? kGreyDT : null,
backgroundColor: modeTheme.isDarkMode ? kGreyDT : null,
selectedItemColor: Theme.of(context).primaryColor,
currentIndex: _currentIndex,
selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),
Expand All @@ -357,7 +367,10 @@ class _MainScreenState extends State<MainScreen>
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(icon: Icon(Icons.rss_feed), label: 'Feeds')
BottomNavigationBarItem(
icon: Icon(Icons.rss_feed),
label: 'Feeds',
)
],
onTap: (index) {
setState(() => _currentIndex = index);
Expand All @@ -374,28 +387,32 @@ class _MainScreenState extends State<MainScreen>
onPressed: () {
if (_currentIndex == 0) {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
return AddBottomSheet(
api: api,
apiRequest: (url) {
ApiRequests.addTorrent(api, url);
},
dialogHint: 'Enter Torrent Url');
});
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
return AddBottomSheet(
api: api,
apiRequest: (url) {
ApiRequests.addTorrent(api, url);
},
dialogHint: 'Enter Torrent Url',
);
},
);
} else {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
return AddBottomSheet(
apiRequest: (url) async {
await ApiRequests.addRSS(api, url);
setState(() {});
},
dialogHint: 'Enter Rss Url');
});
isScrollControlled: true,
context: context,
builder: (BuildContext bc) {
return AddBottomSheet(
apiRequest: (url) async {
await ApiRequests.addRSS(api, url);
setState(() {});
},
dialogHint: 'Enter Rss Url',
);
},
);
}
},
),
Expand Down