728x90
728x170
■ Theme 클래스를 사용해 다크 테마를 설정하는 방법을 보여준다.
▶ main.dart
import 'package:flutter/material.dart';
void main() {
runApp(TestApplication());
}
class TestApplication extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test Application',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
DateTime _selectedDate;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test Application'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('Run'),
color: Colors.blue,
textColor: Colors.white,
onPressed: () {
Future<DateTime> future = showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2018),
lastDate: DateTime(2030),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.dark(),
child: child,
);
},
);
future.then((date) {
setState(() {
_selectedDate = date;
});
});
},
),
Text(
'결과 : $_selectedDate',
),
],
),
),
);
}
}
728x90
그리드형(광고전용)
'Flutter' 카테고리의 다른 글
[FLUTTER] AnimatedContainer 클래스 사용하기 (0) | 2021.04.25 |
---|---|
[FLUTTER] Hero 클래스 사용하기 (0) | 2021.04.25 |
[FLUTTER] InkWell 클래스 사용하기 (0) | 2021.04.25 |
[FLUTTER] GestureDetector 클래스 사용하기 (0) | 2021.04.25 |
[FLUTTER] showTimePicker 함수 : 시간 선택하기 (0) | 2021.04.25 |
[FLUTTER] Future<T> 클래스 : then 메소드 사용하기 (0) | 2021.04.25 |
[FLUTTER] showDatePicker 함수 : 날짜 선택하기 (0) | 2021.04.25 |
[FLUTTER] AlertDialog 클래스 : 알림 대화 상자 사용하기 (0) | 2021.04.25 |
[FLUTTER] DropdownButton 클래스 사용하기 (0) | 2021.04.22 |
[FLUTTER] RadioListTile 클래스 사용하기 (0) | 2021.04.22 |