-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy paththeme.dart
More file actions
56 lines (51 loc) · 1.77 KB
/
theme.dart
File metadata and controls
56 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: bloc.darkThemeEnabled,
initialData: false,
builder: (context, snapshot) => MaterialApp(
debugShowCheckedModeBanner: false,
theme: snapshot.data ? ThemeData.dark() : ThemeData.light(),
home: Scaffold(
appBar: AppBar(
title: Text("Dynamic Theme"),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(70)),
child: new Image.network(
"https://www.gstatic.com/tv/thumb/persons/589228/589228_v9_ba.jpg",
width: 150,
height: 300,
),
),
Padding(
padding: const EdgeInsets.only(left: 10.0, right: 6.0),
child: new Text(
"Hello Mark Zukerberg!!!!!!",
style: TextStyle(
fontSize: 15.0, fontWeight: FontWeight.bold),
),
),
Switch(value: snapshot.data, onChanged: bloc.changeTheme),
],
),
),
)),
);
}
}
class Bloc {
final _themeController = StreamController<bool>();
get changeTheme => _themeController.sink.add;
get darkThemeEnabled => _themeController.stream;
}
final bloc = Bloc();