apollo_flutter 1.0.0 apollo_flutter: ^1.0.0 copied to clipboard
the Apollo service of the Terra platform.
import 'package:apollo_flutter/apollo_theme.dart';
import 'package:apollo_flutter/terra_apollo.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ApolloColorTheme? _colorTheme;
void _initApollo() async {
final apollo = await TerraApollo.getInstance("apollo-flutter");
setState(() {
_colorTheme = apollo.getTheme().colors;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Apollo Flutter example app'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
onPressed: _initApollo,
child: const Text(
'Init Apollo',
),
),
if (_colorTheme != null) ColorThemeView(colorTheme: _colorTheme!)
],
),
),
);
}
}
class ColorThemeView extends StatelessWidget {
final ApolloColorTheme colorTheme;
const ColorThemeView({Key? key, required this.colorTheme}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: SingleChildScrollView(
child: Column(
children: [
ColorSetView(name: "primary", colorSet: colorTheme.primary),
ColorSetView(name: "link", colorSet: colorTheme.link),
ColorSetView(name: "pending", colorSet: colorTheme.pending),
ColorSetView(name: "success", colorSet: colorTheme.success),
ColorSetView(name: "error", colorSet: colorTheme.error),
NeutralColorSetView(colorSet: colorTheme.neutral)
],
),
),
);
}
}
class ColorSetView extends StatelessWidget {
final String name;
final ApolloColorSet colorSet;
const ColorSetView({Key? key, required this.name, required this.colorSet}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: const TextStyle(fontWeight: FontWeight.bold),
),
IntrinsicHeight(
child: Row(
children: [
ColorItemView(name: "50", color: colorSet.color50),
ColorItemView(name: "100", color: colorSet.color100),
ColorItemView(name: "200", color: colorSet.color200),
ColorItemView(name: "500", color: colorSet.color500),
ColorItemView(name: "600", color: colorSet.color600),
ColorItemView(name: "700", color: colorSet.color700),
],
),
),
const SizedBox(height: 24),
],
),
);
}
}
class NeutralColorSetView extends StatelessWidget {
final ApolloNeutralColorSet colorSet;
const NeutralColorSetView({Key? key, required this.colorSet}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Neutral",
style: TextStyle(fontWeight: FontWeight.bold),
),
IntrinsicHeight(
child: Row(
children: [
ColorItemView(name: "white", color: colorSet.white),
ColorItemView(name: "tableHeader", color: colorSet.tableHeader),
ColorItemView(name: "background", color: colorSet.background),
ColorItemView(name: "divider", color: colorSet.divider),
ColorItemView(name: "disable", color: colorSet.disable),
ColorItemView(name: "border", color: colorSet.border),
ColorItemView(name: "placeholder", color: colorSet.placeholder),
ColorItemView(name: "secondaryText", color: colorSet.secondaryText),
ColorItemView(name: "titleText", color: colorSet.titleText),
],
),
),
const SizedBox(height: 24),
],
),
);
}
}
class ColorItemView extends StatelessWidget {
final String name;
final Color color;
const ColorItemView({Key? key, required this.name, required this.color}) : super(key: key);
@override
Widget build(BuildContext context) {
return Expanded(
child: Column(
children: [
Container(
height: 60,
color: color,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: Text(name),
),
],
),
);
}
}