-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support multi gifs Signed-off-by: kuromesi <[email protected]> * handle errors, optimize logic Signed-off-by: kuromesi <[email protected]> --------- Signed-off-by: kuromesi <[email protected]>
- Loading branch information
Showing
13 changed files
with
539 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:landscape/players/gif.dart'; | ||
import 'package:landscape/players/scroll_text.dart'; | ||
import 'package:wakelock_plus/wakelock_plus.dart'; | ||
import 'package:landscape/players/error.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); | ||
return MaterialApp( | ||
title: 'Landscape', | ||
theme: ThemeData( | ||
primarySwatch: Colors.purple, | ||
), | ||
home: const Landscape(), | ||
); | ||
} | ||
} | ||
|
||
class Landscape extends StatefulWidget { | ||
const Landscape({super.key}); | ||
@override | ||
_LandscapeState createState() => _LandscapeState(); | ||
} | ||
|
||
List<Widget> _pages = [ErrorPage(), GifPage(), ScrollTextPage()]; | ||
|
||
Map<String, int> _pagesMap = { | ||
'GIF': 1, | ||
'Scroll Text': 2, | ||
}; | ||
|
||
class _LandscapeState extends State<Landscape> { | ||
bool _isDarkTheme = false; | ||
bool _keepScreenOn = false; | ||
int _pageIndex = 1; | ||
PageController _pageController = PageController(initialPage: 1); | ||
final SharedPreferencesAsync _prefs = SharedPreferencesAsync(); | ||
|
||
@override | ||
void initState() { | ||
_loadPreferences(); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_savePreferences(); | ||
_pageController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
Future<void> _loadPreferences() async { | ||
_isDarkTheme = await _prefs.getBool('isDarkTheme') ?? false; | ||
_keepScreenOn = await _prefs.getBool('keepScreenOn') ?? false; | ||
setState(() { | ||
_isDarkTheme = _isDarkTheme; | ||
_keepScreenOn = _keepScreenOn; | ||
}); | ||
} | ||
|
||
Future<void> _savePreferences() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setBool("isDarkTheme", _isDarkTheme); | ||
await prefs.setBool("keepScreenOn", _keepScreenOn); | ||
} | ||
|
||
void _toggleTheme() { | ||
setState(() { | ||
_isDarkTheme = !_isDarkTheme; | ||
}); | ||
_prefs.setBool("isDarkTheme", _isDarkTheme); | ||
} | ||
|
||
void _showPage(String page) { | ||
setState(() { | ||
_pageIndex = _pagesMap[page] ?? 0; | ||
_pageController.jumpToPage(_pageIndex); | ||
}); | ||
} | ||
|
||
void _toggleKeepScreenOn(BuildContext context) { | ||
_keepScreenOn = !_keepScreenOn; | ||
WakelockPlus.toggle(enable: _keepScreenOn); | ||
setState(() { | ||
_keepScreenOn = _keepScreenOn; | ||
}); | ||
final snackBar = SnackBar( | ||
content: Text(_keepScreenOn ? 'Wakelock Enabled' : 'Wakelock Disabled'), | ||
duration: const Duration(seconds: 2), | ||
); | ||
ScaffoldMessenger.of(context).showSnackBar(snackBar); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData( | ||
primarySwatch: _isDarkTheme ? Colors.grey : Colors.purple, | ||
brightness: _isDarkTheme ? Brightness.dark : Brightness.light, | ||
scaffoldBackgroundColor: _isDarkTheme ? Colors.black : Colors.white, | ||
), | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Landscape'), | ||
actions: [ | ||
IconButton( | ||
icon: | ||
Icon(_isDarkTheme ? Icons.wb_sunny : Icons.nightlight_round), | ||
onPressed: _toggleTheme, | ||
), | ||
Builder( | ||
builder: (context) => IconButton( | ||
icon: Icon(_keepScreenOn ? Icons.lock : Icons.lock_open), | ||
onPressed: () => _toggleKeepScreenOn(context), | ||
), | ||
) | ||
], | ||
), | ||
body: PageView( | ||
physics: NeverScrollableScrollPhysics(), | ||
controller: _pageController, | ||
children: _pages, | ||
), | ||
drawer: Drawer( | ||
child: ListView( | ||
padding: EdgeInsets.zero, | ||
children: <Widget>[ | ||
DrawerHeader( | ||
decoration: BoxDecoration( | ||
color: _isDarkTheme ? Colors.grey[800] : Colors.purple, | ||
), | ||
child: const Text('Players'), | ||
), | ||
ListTile( | ||
title: const Text('GIF'), | ||
onTap: () { | ||
_showPage("GIF"); | ||
}, | ||
), | ||
ListTile( | ||
title: const Text('Scroll Text'), | ||
onTap: () { | ||
_showPage("Scroll Text"); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
|
||
void notify(BuildContext context, String text) { | ||
final snackBar = SnackBar( | ||
content: Text(text), | ||
duration: const Duration(seconds: 2), | ||
); | ||
ScaffoldMessenger.of(context).showSnackBar(snackBar); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,158 +1,6 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:landscape/players/gif.dart'; | ||
import 'package:landscape/players/scroll_text.dart'; | ||
import 'package:wakelock_plus/wakelock_plus.dart'; | ||
import 'package:landscape/players/error.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:landscape/app.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Landscape', | ||
theme: ThemeData( | ||
primarySwatch: Colors.purple, | ||
), | ||
home: const Landscape(), | ||
); | ||
} | ||
} | ||
|
||
class Landscape extends StatefulWidget { | ||
const Landscape({super.key}); | ||
@override | ||
_LandscapeState createState() => _LandscapeState(); | ||
} | ||
|
||
List<Widget> _pages = [ErrorPage(), GifPage(), ScrollTextPage()]; | ||
|
||
Map<String, int> _pagesMap = { | ||
'GIF': 1, | ||
'Scroll Text': 2, | ||
}; | ||
|
||
class _LandscapeState extends State<Landscape> { | ||
bool _isDarkTheme = false; | ||
bool _keepScreenOn = false; | ||
int _pageIndex = 1; | ||
PageController _pageController = PageController(initialPage: 1); | ||
final SharedPreferencesAsync _prefs = SharedPreferencesAsync(); | ||
|
||
@override | ||
void initState() { | ||
_loadPreferences(); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_savePreferences(); | ||
_pageController.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
Future<void> _loadPreferences() async { | ||
_isDarkTheme = await _prefs.getBool('isDarkTheme') ?? false; | ||
_keepScreenOn = await _prefs.getBool('keepScreenOn') ?? false; | ||
setState(() { | ||
_isDarkTheme = _isDarkTheme; | ||
_keepScreenOn = _keepScreenOn; | ||
}); | ||
} | ||
|
||
Future<void> _savePreferences() async { | ||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setBool("isDarkTheme", _isDarkTheme); | ||
await prefs.setBool("keepScreenOn", _keepScreenOn); | ||
} | ||
|
||
void _toggleTheme() { | ||
setState(() { | ||
_isDarkTheme = !_isDarkTheme; | ||
}); | ||
_prefs.setBool("isDarkTheme", _isDarkTheme); | ||
} | ||
|
||
void _showPage(String page) { | ||
setState(() { | ||
_pageIndex = _pagesMap[page] ?? 0; | ||
_pageController.jumpToPage(_pageIndex); | ||
}); | ||
} | ||
|
||
void _toggleKeepScreenOn(BuildContext context) { | ||
_keepScreenOn = !_keepScreenOn; | ||
WakelockPlus.toggle(enable: _keepScreenOn); | ||
setState(() { | ||
_keepScreenOn = _keepScreenOn; | ||
}); | ||
final snackBar = SnackBar( | ||
content: Text(_keepScreenOn ? 'Wakelock Enabled' : 'Wakelock Disabled'), | ||
duration: const Duration(seconds: 2), | ||
); | ||
ScaffoldMessenger.of(context).showSnackBar(snackBar); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData( | ||
primarySwatch: _isDarkTheme ? Colors.grey : Colors.purple, | ||
brightness: _isDarkTheme ? Brightness.dark : Brightness.light, | ||
scaffoldBackgroundColor: _isDarkTheme ? Colors.black : Colors.white, | ||
), | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Landscape'), | ||
actions: [ | ||
IconButton( | ||
icon: | ||
Icon(_isDarkTheme ? Icons.wb_sunny : Icons.nightlight_round), | ||
onPressed: _toggleTheme, | ||
), | ||
Builder( | ||
builder: (context) => IconButton( | ||
icon: Icon(_keepScreenOn ? Icons.lock : Icons.lock_open), | ||
onPressed: () => _toggleKeepScreenOn(context), | ||
), | ||
) | ||
], | ||
), | ||
body: PageView( | ||
physics: NeverScrollableScrollPhysics(), | ||
controller: _pageController, | ||
children: _pages, | ||
), | ||
drawer: Drawer( | ||
child: ListView( | ||
padding: EdgeInsets.zero, | ||
children: <Widget>[ | ||
DrawerHeader( | ||
decoration: BoxDecoration( | ||
color: _isDarkTheme ? Colors.grey[800] : Colors.purple, | ||
), | ||
child: const Text('Players'), | ||
), | ||
ListTile( | ||
title: const Text('GIF'), | ||
onTap: () { | ||
_showPage("GIF"); | ||
}, | ||
), | ||
ListTile( | ||
title: const Text('Scroll Text'), | ||
onTap: () { | ||
_showPage("Scroll Text"); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.