Skip to content

Commit df76b6a

Browse files
committed
Fixed some UI problems
1 parent ef89350 commit df76b6a

File tree

3 files changed

+179
-71
lines changed

3 files changed

+179
-71
lines changed

lib/pages/home_screen.dart

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
33
import 'package:plot_generator/bloc/plotto_bloc.dart';
4+
import 'package:plot_generator/widgets/narrow_screen.dart';
5+
6+
import '../widgets/wide_screen.dart';
47

58
class HomeScreen extends StatelessWidget {
69
const HomeScreen({Key? key}) : super(key: key);
@@ -16,77 +19,13 @@ class HomeScreen extends StatelessWidget {
1619
),
1720
onPressed: () => bloc.add(SkeletonRequested()),
1821
),
19-
body: BlocBuilder<PlottoBloc, PlottoState>(
20-
builder: (context, state) {
21-
if (state is PlottoInitial) {
22-
bloc.add(LoadRequested());
23-
return Center(
24-
child: Text('Please Wait'),
25-
);
26-
}
27-
if (state is PlottoLoading) {
28-
return Center(
29-
child: Text('Loading Please Wait...'),
30-
);
31-
}
32-
if (state is PlottoLoaded) {
33-
return Center(
34-
child: Text('Ready! Please click the FAB ro start.'),
35-
);
36-
}
37-
if (state is PlottoGenerated) {
38-
return Row(
39-
children: [
40-
Expanded(
41-
child: Column(
42-
children: [
43-
Card(
44-
child: ListTile(
45-
title: Text(state.masterClauseA),
46-
),
47-
),
48-
Card(
49-
child: ListTile(
50-
title: Text(state.masterClauseB),
51-
),
52-
),
53-
Card(
54-
child: ListTile(
55-
title: Text(state.masterClauseC),
56-
),
57-
),
58-
],
59-
),
60-
),
61-
Expanded(
62-
child: ListView.builder(
63-
shrinkWrap: true,
64-
itemCount: state.conflicts.length,
65-
itemBuilder: (context, index) {
66-
return Card(
67-
child: ListTile(
68-
leading: IconButton(
69-
icon: Icon(Icons.arrow_back),
70-
onPressed: () =>
71-
bloc.add(LeadInRequested(index: index)),
72-
),
73-
title: Text(state.conflicts[index]),
74-
trailing: IconButton(
75-
icon: Icon(Icons.arrow_forward),
76-
onPressed: () =>
77-
bloc.add(CarryOnRequested(index: index)),
78-
),
79-
),
80-
);
81-
},
82-
),
83-
)
84-
],
85-
);
86-
}
87-
return Center(
88-
child: Text('Unknown state.'),
89-
);
22+
body: LayoutBuilder(
23+
builder: (BuildContext context, BoxConstraints constraints) {
24+
MediaQueryData mediaQuery = MediaQuery.of(context);
25+
if (mediaQuery.size.width > 600)
26+
return WideScreen();
27+
else
28+
return NarrowScreen();
9029
},
9130
),
9231
);

lib/widgets/narrow_screen.dart

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
4+
import '../bloc/plotto_bloc.dart';
5+
6+
class NarrowScreen extends StatelessWidget {
7+
const NarrowScreen({Key? key}) : super(key: key);
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return BlocBuilder<PlottoBloc, PlottoState>(
12+
builder: (context, state) {
13+
PlottoBloc bloc = BlocProvider.of(context);
14+
if (state is PlottoInitial) {
15+
bloc.add(LoadRequested());
16+
return Center(
17+
child: Text('Please Wait'),
18+
);
19+
}
20+
if (state is PlottoLoading) {
21+
return Center(
22+
child: Text('Loading Please Wait...'),
23+
);
24+
}
25+
if (state is PlottoLoaded) {
26+
return Center(
27+
child: Text('Ready! Please click the FAB ro start.'),
28+
);
29+
}
30+
if (state is PlottoGenerated) {
31+
return Column(
32+
children: [
33+
Card(
34+
child: ListTile(
35+
title: Text(state.masterClauseA),
36+
),
37+
),
38+
Card(
39+
child: ListTile(
40+
title: Text(state.masterClauseB),
41+
),
42+
),
43+
Expanded(
44+
child: ListView.builder(
45+
shrinkWrap: true,
46+
itemCount: state.conflicts.length,
47+
itemBuilder: (context, index) {
48+
return Card(
49+
child: ListTile(
50+
leading: IconButton(
51+
icon: Icon(Icons.arrow_back),
52+
onPressed: () =>
53+
bloc.add(LeadInRequested(index: index)),
54+
),
55+
title: Text(state.conflicts[index]),
56+
trailing: IconButton(
57+
icon: Icon(Icons.arrow_forward),
58+
onPressed: () =>
59+
bloc.add(CarryOnRequested(index: index)),
60+
),
61+
),
62+
);
63+
},
64+
),
65+
),
66+
Card(
67+
child: ListTile(
68+
title: Text(state.masterClauseC),
69+
),
70+
)
71+
],
72+
);
73+
}
74+
return Center(
75+
child: Text('Unknown state.'),
76+
);
77+
},
78+
);
79+
}
80+
}

lib/widgets/wide_screen.dart

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
4+
import '../bloc/plotto_bloc.dart';
5+
6+
class WideScreen extends StatelessWidget {
7+
const WideScreen({
8+
Key? key,
9+
}) : super(key: key);
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return BlocBuilder<PlottoBloc, PlottoState>(
14+
builder: (context, state) {
15+
PlottoBloc bloc = BlocProvider.of(context);
16+
if (state is PlottoInitial) {
17+
bloc.add(LoadRequested());
18+
return Center(
19+
child: Text('Please Wait'),
20+
);
21+
}
22+
if (state is PlottoLoading) {
23+
return Center(
24+
child: Text('Loading Please Wait...'),
25+
);
26+
}
27+
if (state is PlottoLoaded) {
28+
return Center(
29+
child: Text('Ready! Please click the FAB ro start.'),
30+
);
31+
}
32+
if (state is PlottoGenerated) {
33+
return Row(
34+
children: [
35+
Expanded(
36+
child: Column(
37+
mainAxisAlignment: MainAxisAlignment.center,
38+
children: [
39+
Card(
40+
child: ListTile(
41+
title: Text(state.masterClauseA),
42+
),
43+
),
44+
Card(
45+
child: ListTile(
46+
title: Text(state.masterClauseB),
47+
),
48+
),
49+
Card(
50+
child: ListTile(
51+
title: Text(state.masterClauseC),
52+
),
53+
),
54+
],
55+
),
56+
),
57+
Expanded(
58+
child: ListView.builder(
59+
shrinkWrap: true,
60+
itemCount: state.conflicts.length,
61+
itemBuilder: (context, index) {
62+
return Card(
63+
child: ListTile(
64+
leading: IconButton(
65+
icon: Icon(Icons.arrow_back),
66+
onPressed: () =>
67+
bloc.add(LeadInRequested(index: index)),
68+
),
69+
title: Text(state.conflicts[index]),
70+
trailing: IconButton(
71+
icon: Icon(Icons.arrow_forward),
72+
onPressed: () =>
73+
bloc.add(CarryOnRequested(index: index)),
74+
),
75+
),
76+
);
77+
},
78+
),
79+
)
80+
],
81+
);
82+
}
83+
return Center(
84+
child: Text('Unknown state.'),
85+
);
86+
},
87+
);
88+
}
89+
}

0 commit comments

Comments
 (0)