night 0.0.2
night: ^0.0.2 copied to clipboard
移动端夜色模式适配.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:night/night.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int nightMode = 404;
@override
void initState() {
super.initState();
initModeCode();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initModeCode() async {
int mode;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
mode = await Night.getDefaultNightMode;
} on PlatformException {
mode = -400;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
nightMode = mode;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $nightMode\n'),
),
),
);
}
}