Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created December 5, 2018 17:52
Show Gist options
  • Save jonahwilliams/a0c278572f9bdce77104a47e39b4a72a to your computer and use it in GitHub Desktop.
Save jonahwilliams/a0c278572f9bdce77104a47e39b4a72a to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State createState() => MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
SystemUiOverlayStyle _currentStyle = SystemUiOverlayStyle.light;
void _changeColor(r, g, b) {
setState(() {
_currentStyle = SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Color.fromRGBO(r, g, b, 1.0),
);
});
}
void _showDialog() async {
_changeColor(32, 205, 125);
await Future.delayed(const Duration(seconds: 5));
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Something went wrong!'),
content: const Text('Be sure you are connected to the Device'),
actions: [
FlatButton(
child: const Text('Ok'),
onPressed: () {
Navigator.pop(context);
_changeColor(244, 128, 36);
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion(
sized: false,
value: _currentStyle,
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: RaisedButton(
child: const Text('Change Color'),
color: Color.fromRGBO(32, 205, 125, 1.0),
onPressed: _showDialog,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment